Python Forum
Libraries installed with pipenv, but ModuleNotFoundError returned
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Libraries installed with pipenv, but ModuleNotFoundError returned
#1
I am using pipenv v2021.5.29 to create an environment for running a script. I have a requirements.txt script with all the packages needed. The contents of the requirements.txt are at bottom of post.

I installed pipenv with
python3 -m pip install --user pipenv
Then I ran:
pipenv shell
Output:
Creating a virtualenv for this project... Pipfile: C:\Users\john\Documents\programming\imseg\Pipfile Using C:/OSGeo4W/bin/python3.exe (3.9.5) to create virtualenv... [ ===] Creating virtual environment...created virtual environment CPython3.9.5.final.0-64 in 742ms creator CPython3Windows(dest=C:\Users\john\.virtualenvs\imseg-cT2t34Fc, clear=False, no_vcs_ignore=False, global=False) seeder FromAppData(download=False, pip=bundle, setuptools=bundle, wheel=bundle, via=copy, app_data_dir=C:\Users\john\AppData\Local\pypa\virtualenv) added seed packages: pip==21.2.2, setuptools==57.4.0, wheel==0.36.2 activators BashActivator,BatchActivator,FishActivator,PowerShellActivator,PythonActivator Successfully created virtual environment! Virtualenv location: C:\Users\john\.virtualenvs\imseg-cT2t34Fc Launching subshell in virtual environment... Microsoft Windows [Version 10.0.19043.1165] (c) Microsoft Corporation. All rights reserved.
I used
pipenv install
Output:
Installing dependencies from Pipfile.lock (a70a42)... ================================ 19/19 - 00:00:37
It seems like the requirements were installed without problem. I confirm this with
pipenv graph
Output:
Cython==0.29.24 GitPython==3.1.18 - gitdb [required: >=4.0.1,<5, installed: 4.0.7] - smmap [required: >=3.0.1,<5, installed: 4.0.0] matplotlib==3.4.2 - cycler [required: >=0.10, installed: 0.10.0] - six [required: Any, installed: 1.16.0] - kiwisolver [required: >=1.0.1, installed: 1.3.1] - numpy [required: >=1.16, installed: 1.21.1] - pillow [required: >=6.2.0, installed: 8.3.1] - pyparsing [required: >=2.2.1, installed: 2.4.7] - python-dateutil [required: >=2.7, installed: 2.8.2] - six [required: >=1.5, installed: 1.16.0] opencv-python==4.5.3.56 - numpy [required: >=1.19.3, installed: 1.21.1] pandas==1.3.1 - numpy [required: >=1.17.3, installed: 1.21.1] - python-dateutil [required: >=2.7.3, installed: 2.8.2] - six [required: >=1.5, installed: 1.16.0] - pytz [required: >=2017.3, installed: 2021.1] rawpy==0.16.0 - numpy [required: Any, installed: 1.21.1] torchvision==0.10.0 - numpy [required: Any, installed: 1.21.1] - pillow [required: >=5.3.0, installed: 8.3.1] - torch [required: ==1.9.0, installed: 1.9.0] - typing-extensions [required: Any, installed: 3.10.0.0]
However, when I run my script with
python3 model_to_green_value.py
I get this
Error:
Traceback (most recent call last): File "C:\Users\john\Documents\programming\imseg\model_to_green_value.py", line 14, in <module> import matplotlib.pyplot as plt ModuleNotFoundError: No module named 'matplotlib'
I'm using Windows 10. I'm new to virtual environments and pipenv. I thought that installing pipenv and using it the way I have is the correct procedure for recreating the environment in which to run the script, so I don't know why this error occurs. How do I fix this?

requirements.txt:
Output:
# # These requirements were autogenerated by pipenv # To regenerate from the project's Pipfile, run: # # pipenv lock --requirements # -i https://pypi.org/simple cycler==0.10.0 cython==0.29.24; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' gitdb==4.0.7; python_version >= '3.4' gitpython==3.1.18 kiwisolver==1.3.1; python_version >= '3.6' matplotlib==3.4.2 numpy==1.21.1 opencv-python==4.5.3.56 pandas==1.3.1 pillow==8.3.1 pyparsing==2.4.7; python_version >= '2.6' and python_version not in '3.0, 3.1, 3.2, 3.3' python-dateutil==2.8.2; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' pytz==2021.1 rawpy==0.16.0 six==1.16.0; python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3' smmap==4.0.0; python_version >= '3.5' torch==1.9.0 torchvision==0.10.0 typing-extensions==3.10.0.0; python_version < '3.8'
Reply
#2
(Sep-04-2021, 01:01 AM)jpncsu Wrote: However, when I run my script with
python3 model_to_green_value.py
You most do this in shell when active,usually on Windows there is python and not python3
When in shell test with python -c "import sys;print(sys.executable)"
G:\
λ python -c "import sys;print(sys.executable)"
G:\-EtzfjxZG\Scripts\python.exe

G:\
λ pip -V
pip 21.2.3 from G:\-EtzfjxZG\lib\site-packages\pip (python 3.9)
So now over is active and use python version and packages install to this environment.
If i exit out.
G:\
λ exit

G:\div_code\mat_env
λ python -c "import sys;print(sys.executable)"
C:\python39\python.exe

G:\div_code\mat_env
λ pip -V
pip 21.2.4 from c:\python39\lib\site-packages\pip (python 3.9)
So if you outside of shell(active) most point to python version in environment,like eg from editor or it will use default Winnows version.

I never use pipenv anymore had to much issues.
venv build into Python is easy to use,can use pipx for more options.
The best 3-pary of this is in my option Poetry
Reply
#3
Hi, snippsat. Thanks for the reply.

(Sep-04-2021, 04:35 PM)snippsat Wrote:
(Sep-04-2021, 01:01 AM)jpncsu Wrote: However, when I run my script with
python3 model_to_green_value.py
You most do this in shell when active,usually on Windows there is python and not python3
I got used to using "python3" because I had two versions of Python on my machine.

(Sep-04-2021, 04:35 PM)snippsat Wrote: I never use pipenv anymore had to much issues.
venv build into Python is easy to use,can use pipx for more options.
The best 3-pary of this is in my option Poetry
Thank you for mentioning this. I am not very experienced programmer and have almost no experience with package/dependency management. My advisor told me about pipenv and I thought it would be fine. I will investigate Poetry further.

I did figure out how to deal with my problem in pipenv. I need to run the script with
pipenv run python script.py
instead of
python script.py
That runs the script with the pipenv environment/settings.

jpncsu
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting "name 'get_weather' is not defined error and no json_data returned? trthskr4 6 730 Sep-14-2021, 09:55 AM
Last Post: trthskr4
  setting up pipenv tobiasfw 1 673 Jan-13-2021, 05:46 PM
Last Post: buran
  ModuleNotFoundError when application is not installed via setup.py bytebutcher 3 879 Jan-08-2021, 10:28 AM
Last Post: Gribouillis
  Managing dependencies with pipenv t4keheart 6 1,299 Aug-05-2020, 12:39 AM
Last Post: t4keheart
  Exception: Returned Type Mismatch Error devansing 1 2,499 Mar-06-2020, 07:26 PM
Last Post: ndc85430
  How to use a returned value? t4keheart 12 2,238 Jan-16-2020, 06:54 AM
Last Post: perfringo
  Strange Characters in JSON returned string fioranosnake 4 2,519 Dec-02-2019, 07:25 PM
Last Post: fioranosnake
  Not all data returned from sys.argv ecdhyne 2 1,361 Sep-05-2019, 08:27 PM
Last Post: buran
  I always get 'None' returned. Confused. What did I miss? jpezz 2 1,233 Apr-07-2019, 10:06 AM
Last Post: jpezz
  How to resolve 404 returned from web method when not running on localhost littleGreenDude 3 1,607 Feb-05-2019, 09:01 PM
Last Post: littleGreenDude

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020