Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem importing local module (ImportError: No module named reinas) #3

Open
pperez opened this issue Apr 21, 2013 · 5 comments
Open

Comments

@pperez
Copy link

pperez commented Apr 21, 2013

Hi, i am using benchy and trying to do multiple benchmarks to a function (The n queens problem), i have a module named 'reinas' and this code for benchmarking:

#!/usr/bin/env python

import matplotlib.pyplot as plt
from benchy.api import Benchmark, BenchmarkSuite, BenchmarkRunner

#casos = (8, 10, 15, 20, 30, 50, 70, 100)
casos = [i for i in range(2,8)]

# Using the benchy library
setup = 'from reinas import nreinas'
suite = BenchmarkSuite()

for n in casos:
stmt = 'resultado = nreinas(' + str(n) + ')'
benchmark = Benchmark(stmt, setup, name = 'nreinas(' + str(n) + ')')
suite.append(benchmark)

runner = BenchmarkRunner(benchmarks=suite, tmp_dir='.', name= 'Tarea de las n reinas')
n_benchs, results = runner.run()
fig = runner.plot_relative(results, horizontal=True)
plt.savefig('%s_r.png' % runner.name, bbox_inches='tight')


runner.plot_absolute(results, horizontal=False)
plt.savefig('%s.png' % runner.name) # bbox_inches='tight')

if i run this i just get an error:

(env)pperez@hydrogen:~/code/nreinas$ python reinas_benchmark.py
Running benchmark nreinas(2) ...
python /home/pperez/code/nreinas/env/src/benchy/benchy/run_benchmarks.py ./benchmark.pickle ./results.pickle
stdout: 
Traceback (most recent call last):
  File "/home/pperez/code/nreinas/env/src/benchy/benchy/run_benchmarks.py", line 12, in <module>
    res = benchmark.run()
  File "/home/pperez/code/nreinas/env/src/benchy/benchy/benchmark.py", line 74, in run
    results['memory'] = self.run_memit()
  File "/home/pperez/code/nreinas/env/src/benchy/benchy/benchmark.py", line 97, in run_memit
    ns = self._setup()
  File "/home/pperez/code/nreinas/env/src/benchy/benchy/benchmark.py", line 28, in _setup
    exec self.setup in ns
  File "<string>", line 1, in <module>
ImportError: No module named reinas

Traceback (most recent call last):
  File "/home/pperez/code/nreinas/env/src/benchy/benchy/run_benchmarks.py", line 12, in <module>
    res = benchmark.run()
  File "/home/pperez/code/nreinas/env/src/benchy/benchy/benchmark.py", line 74, in run
    results['memory'] = self.run_memit()
  File "/home/pperez/code/nreinas/env/src/benchy/benchy/benchmark.py", line 97, in run_memit
    ns = self._setup()
  File "/home/pperez/code/nreinas/env/src/benchy/benchy/benchmark.py", line 28, in _setup
    exec self.setup in ns
  File "<string>", line 1, in <module>
ImportError: No module named reinas

Traceback (most recent call last):
  File "reinas_benchmark.py", line 20, in <module>
    fig = runner.plot_relative(results, horizontal=True)
  File "/home/pperez/code/nreinas/env/src/benchy/benchy/runner.py", line 231, in plot_relative
    ax.set_ylim([ax_pos[0] - 0.25, ax_pos[-1] + 1])
IndexError: index 0 is out of bounds for axis 0 with size 0

I don't know if this a problem with virtualenv or what, but if i run the benchmarks with PYTHONPATH='.' python reinas_benchmark.py' it works like a charm.

@pperez
Copy link
Author

pperez commented Apr 21, 2013

Oh, i forgot, the reinas module is in the same directory (/home/pperez/code/nreinas)

@marcelcaraciolo
Copy link
Contributor

Hi @janitux how are you ? Thanks for your reply. I will check this bug, but with pythonpath everything goes well 100% ? :)

@pperez
Copy link
Author

pperez commented Apr 21, 2013

Yes, it works like a charm :)

(env)pperez@hydrogen:~/code/nreinas$ PYTHONPATH='.' python reinas_benchmark.py
Running benchmark nreinas(0) ...
python /home/pperez/code/nreinas/env/src/benchy/benchy/run_benchmarks.py ./benchmark.pickle ./results.pickle
stdout: 1
1

Running benchmark nreinas(1) ...
python /home/pperez/code/nreinas/env/src/benchy/benchy/run_benchmarks.py ./benchmark.pickle ./results.pickle
stdout: 1
1

Running benchmark nreinas(2) ...
python /home/pperez/code/nreinas/env/src/benchy/benchy/run_benchmarks.py ./benchmark.pickle ./results.pickle
stdout: 0
0

Running benchmark nreinas(3) ...
python /home/pperez/code/nreinas/env/src/benchy/benchy/run_benchmarks.py ./benchmark.pickle ./results.pickle
stdout: 0
0

Running benchmark nreinas(4) ...
python /home/pperez/code/nreinas/env/src/benchy/benchy/run_benchmarks.py ./benchmark.pickle ./results.pickle
stdout: 2
2

@marcelcaraciolo
Copy link
Contributor

@janitux and the graphs are workin great ? Please any improvements let me know!

@pperez
Copy link
Author

pperez commented Apr 21, 2013

Yes, they are working great :)
I'm just curious about this, because if i try to import the module on my benchmark file it does import it correctly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants