Skip to content

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

Description

@pperez

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions