是什么导致安装了pipenv的Python包在脚本中调用时找不到?



在安装Python 3.9.5和pipenv 2021.5.29的Windows 10机器上。In apipenv shell:

Creating a virtualenv for this project...
Pipfile: C:UsersjpDocumentsprogrammingimsegPipfile
Using C:/OSGeo4W/bin/python.exe (3.9.5) to create virtualenv...
[ ===] Creating virtual environment...created virtual environment CPython3.9.5.final.0-64 in 612ms
creator CPython3Windows(dest=C:Usersjp.virtualenvsimseg-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:UsersjpAppDataLocalpypavirtualenv)
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:Usersjp.virtualenvsimseg-cT2t34Fc
Launching subshell in virtual environment...
Microsoft Windows [Version 10.0.19043.1165]
(c) Microsoft Corporation. All rights reserved.

我用的是pipenv install。这将返回:

(imseg-cT2t34Fc) C:UsersjpDocumentsprogrammingimseg>pipenv install
Installing dependencies from Pipfile.lock (684440)...
================================ 19/19 - 00:01:02

pipenv graph:

(imseg-cT2t34Fc) C:UsersjpDocumentsprogrammingimseg>pipenv graph
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]

然而,当我尝试调用为其创建环境的脚本时,我得到:

(imseg-cT2t34Fc) C:UsersjpDocumentsprogrammingimsegsrc>python3 model.py
Traceback (most recent call last):
File "C:UsersjpDocumentsprogrammingimsegsrcmodel.py", line 14, in <module>
import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'

I read and try

pip install pipx
pipx install pipenv

,问题没有变化。我的管道环境有什么问题?

编辑:where python3回报:

C:OSGeo4Wbinpython3.exe
C:OSGeo4WappsPython39python3.exe
C:UsersjpAppDataLocalMicrosoftWindowsAppspython3.exe

编辑(# 2):我不清楚python可执行文件应该存在于哪里?我想我不明白虚拟环境的意思。如果python可执行文件应该存在于虚拟环境中。为什么python可执行文件没有安装在虚拟环境中?开始吗?pipenv网站只是说有python和我安装为pip3 install --user pipenv,所以它似乎应该工作。我还在想如何解决这个问题。

答案很简单。调用Python可执行文件的行应该是

pipenv run python model.py

不是

python model.py

正如对这个问题的公认答案所指出的那样。

相关内容

  • 没有找到相关文章

最新更新