AllenDowney / ModSimPy

Text and supporting code for Modeling and Simulation in Python
https://allendowney.github.io/ModSimPy/
MIT License
823 stars 1.76k forks source link

Errors on importing library #45

Closed hwsamuel closed 3 years ago

hwsamuel commented 5 years ago

After following the installation instructions, I did import modsim and got the following errors (differentiated by Python 2.7 & 3.6). I'm running these on Anaconda 4.7.5

Python 3.6

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\hsamuel\AppData\Local\Continuum\anaconda2\envs\py36\lib\site-packages\modsim\__init__.py", line 1, in <module>
    from .modsim import *
  File "C:\Users\hsamuel\AppData\Local\Continuum\anaconda2\envs\py36\lib\site-packages\modsim\modsim.py", line 38, in <module>
    from pint.errors import UnitStrippedWarning
ImportError: cannot import name 'UnitStrippedWarning'

Python 2.7

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\hsamuel\AppData\Local\Continuum\anaconda2\lib\site-packages\modsim\__init__.py", line 1, in <module>
    from .modsim import *
  File "C:\Users\hsamuel\AppData\Local\Continuum\anaconda2\lib\site-packages\modsim\modsim.py", line 1668
    def Vector(*args, units=None):
                          ^
SyntaxError: invalid syntax
eo1989 commented 4 years ago

Yeah running the cells in the chapter 1 Jupyter notebooks does the same for me. pip3 search doesn't find anything named modsim, and thus trying to pip3 install modsim just returns errors. running python setup.py install within the cloned repo, even creating a new virtualenv just for that directory, didnt help. the notebooks still state theres no module named modsim. ¯_(ツ)_/¯

tdatu commented 4 years ago

Yeah running the cells in the chapter 1 Jupyter notebooks does the same for me. pip3 search doesn't find anything named modsim, and thus trying to pip3 install modsim just returns errors. running python setup.py install within the cloned repo, even creating a new virtualenv just for that directory, didnt help. the notebooks still state theres no module named modsim. ¯(ツ)

modsim was installed in my system in this directory: /Users//Library/Python//lib/python/site-packages/

However, I also encounter some runtime errors when opening chapter2 notebook. Then I opened python3 interactive shell, then imported modsim. This is the error that I got: File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/linecache.py", line 48, in getlines for mod in sys.modules.values(): RuntimeError: dictionary changed size during iteration

gerdis commented 4 years ago

After following the installation instructions, I did import modsim and got the following errors (differentiated by Python 2.7 & 3.6). I'm running these on Anaconda 4.7.5

Python 3.6

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\hsamuel\AppData\Local\Continuum\anaconda2\envs\py36\lib\site-packages\modsim\__init__.py", line 1, in <module> from .modsim import * File "C:\Users\hsamuel\AppData\Local\Continuum\anaconda2\envs\py36\lib\site-packages\modsim\modsim.py", line 38, in <module> from pint.errors import UnitStrippedWarning ImportError: cannot import name 'UnitStrippedWarning'

Python 2.7

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\hsamuel\AppData\Local\Continuum\anaconda2\lib\site-packages\modsim\__init__.py", line 1, in <module> from .modsim import * File "C:\Users\hsamuel\AppData\Local\Continuum\anaconda2\lib\site-packages\modsim\modsim.py", line 1668 def Vector(*args, units=None): ^ SyntaxError: invalid syntax

When using modsim in Python 2.7, the issue seems to be the order of the arguments in the function header in line 1668 (default argument has to come before *args).

AllenDowney commented 3 years ago

Since many people have had problems with this, I have simplified things for Version 4. Instead of installing the ModSim library, the notebooks are set up to download modsim.py if needed. Also, the notebooks work on Colab now, so people can run them in a browser without installing anything. Hopefully, that will make it easier to get started.