5

I have installed Simpy, and I use Python 3.5. I have the same error:

>>> env = simpy.Environment()
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in <module>
    env = simpy.Environment()
AttributeError: module 'simpy' has no attribute 'Environment'

It lets me import simpy, but when I do env = simpy.Environment() it prints this error.

I have tried uninstalling it, reinstalling, using in the terminal, in the Python's IDLE, in other IDLEs...

The whole code is (from the tutorial):

>>> def car(env):
...     while True:
...         print('Start parking at %d' % env.now)
...         parking_duration = 5
...         yield env.timeout(parking_duration)
...
...         print('Start driving at %d' % env.now)
...         trip_duration = 2
...         yield env.timeout(trip_duration)

>>> import simpy
>>> env = simpy.Environment()

And then the error pops-up.

EDIT (solved):

I had a file named simpy.py in the same folder. I removed it, and now works perfectly. The code now is:

>>> def car(env):
...    while True:
...        print('Start parking at %d' % env.now)
...        parking_duration = 5
...        yield env.timeout(parking_duration)
...
...        print('Start driving at %d' % env.now)
...        trip_duration = 2
...        yield env.timeout(trip_duration)

>>> import simpy
>>> env = simpy.Environment()
>>> env.process(car(env))
>>> env.run(until=15)

And the output:

Start parking at 0
Start driving at 5
Start parking at 7
Start driving at 12
Start parking at 14
plr
  • 244
  • 1
  • 15
  • Which OS do you use? Have you taken a look into the site-packages folder if nothing from SimPy remains there after an uninstall? – Stefan Scherfke Oct 22 '15 at 09:09
  • 1
    Or does one of the dirs in sys.path (e.g., your current working dir) contain a file called simpy.py? You can also try "print(simpy.__file__)". – Stefan Scherfke Oct 22 '15 at 09:16
  • Thanks for updating your question with your solution. I did exactly this silly thing, too. Consider adding your solution as the answer and accepting it. – Metropolis Nov 05 '21 at 21:28

1 Answers1

0

I had a file named simpy.py in the same folder. I removed it, and now works perfectly. The code now is:

>>> def car(env):
...    while True:
...        print('Start parking at %d' % env.now)
...        parking_duration = 5
...        yield env.timeout(parking_duration)
...
...        print('Start driving at %d' % env.now)
...        trip_duration = 2
...        yield env.timeout(trip_duration)

>>> import simpy
>>> env = simpy.Environment()
>>> env.process(car(env))
>>> env.run(until=15)

And the output:

Start parking at 0
Start driving at 5
Start parking at 7
Start driving at 12
Start parking at 14
plr
  • 244
  • 1
  • 15