[英]Module is not found when trying to import it and running a virtual environment (venv)
I am currently using a virtual environment (venv) with python. The "venv" directory is inside my project folder by standard convention.我目前正在使用 python 的虚拟环境 (venv)。按照标准约定,“venv”目录位于我的项目文件夹中。
My project folder contains multiple different modules.我的项目文件夹包含多个不同的模块。
I have a jupyter notebook that has multiple import statements in the beginning.我有一个 jupyter notebook,开头有多个 import 语句。 One of the import statements calls one of my other custom-made modules.其中一个导入语句调用我的其他定制模块之一。 This certain module imports tensorflow. When I call pip3 list -V
in the terminal, I get:这个特定模块导入 tensorflow。当我在终端中调用pip3 list -V
时,我得到:
Package Version
----------------------- ---------
absl-py 0.13.0
anyio 3.3.0
appnope 0.1.2
argon2-cffi 20.1.0
astunparse 1.6.3
attrs 21.2.0
autopep8 1.5.7
Babel 2.9.1
backcall 0.2.0
bleach 4.0.0
cachetools 4.2.2
certifi 2021.5.30
cffi 1.14.6
charset-normalizer 2.0.4
cycler 0.10.0
debugpy 1.4.1
decorator 5.0.9
defusedxml 0.7.1
entrypoints 0.3
gast 0.3.3
google-auth 1.34.0
google-auth-oauthlib 0.4.5
google-pasta 0.2.0
grpcio 1.39.0
h5py 2.10.0
idna 3.2
ipykernel 6.2.0
ipython 7.26.0
ipython-genutils 0.2.0
ipywidgets 7.6.3
jedi 0.18.0
Jinja2 3.0.1
json5 0.9.6
jsonschema 3.2.0
jupyter-client 6.1.12
jupyter-core 4.7.1
jupyter-server 1.10.2
jupyterlab 3.1.7
jupyterlab-pygments 0.1.2
jupyterlab-server 2.7.0
jupyterlab-widgets 1.0.0
Keras-Preprocessing 1.1.2
kiwisolver 1.3.1
Markdown 3.3.4
MarkupSafe 2.0.1
matplotlib 3.4.3
matplotlib-inline 0.1.2
mistune 0.8.4
nbclassic 0.3.1
nbclient 0.5.4
nbconvert 6.1.0
nbformat 5.1.3
nest-asyncio 1.5.1
notebook 6.4.3
numpy 1.18.5
oauthlib 3.1.1
opt-einsum 3.3.0
packaging 21.0
pandocfilters 1.4.3
parso 0.8.2
pexpect 4.8.0
pickleshare 0.7.5
Pillow 8.3.1
pip 21.2.4
prometheus-client 0.11.0
prompt-toolkit 3.0.19
protobuf 3.17.3
ptyprocess 0.7.0
pyasn1 0.4.8
pyasn1-modules 0.2.8
pycodestyle 2.7.0
pycparser 2.20
Pygments 2.10.0
pyparsing 2.4.7
pyrsistent 0.18.0
python-dateutil 2.8.2
pytz 2021.1
pyzmq 22.2.1
requests 2.26.0
requests-oauthlib 1.3.0
requests-unixsocket 0.2.0
rsa 4.7.2
scipy 1.4.1
Send2Trash 1.8.0
setuptools 49.2.1
six 1.16.0
sniffio 1.2.0
tensorboard 2.6.0
tensorboard-data-server 0.6.1
tensorboard-plugin-wit 1.8.0
tensorflow 2.3.0
tensorflow-estimator 2.3.0
termcolor 1.1.0
terminado 0.11.0
testpath 0.5.0
toml 0.10.2
tornado 6.1
traitlets 5.0.5
urllib3 1.26.6
wcwidth 0.2.5
webencodings 0.5.1
websocket-client 1.2.1
Werkzeug 2.0.1
wheel 0.37.0
widgetsnbextension 3.5.1
wrapt 1.12.1
However, when I try to import my module that contains tensorflow I get ModuleNotFoundError: No module named 'tensorflow'
.但是,当我尝试导入包含 tensorflow 的模块时,我得到ModuleNotFoundError: No module named 'tensorflow'
。 We can clearly see that tensorflow has been installed by pip3.我们可以清楚的看到tensorflow已经被pip3安装好了。 What's my problem here?我这里有什么问题?
I am new to programming in general and would appreciate some guidance here.我是一般编程的新手,希望能在这里得到一些指导。 I have looked into the PYTHONPATH variable and am trying to understand it.我查看了 PYTHONPATH 变量并试图理解它。 I am also confused with this since I am implementing a virtual environment here.我也对此感到困惑,因为我在这里实现了一个虚拟环境。 I am using MacOS.我正在使用 MacOS。
You may be running your jupyter notebook from a different virtual environment.您可能正在从不同的虚拟环境运行您的 jupyter notebook。 So if you are running jupyter from conda, you need to shut it down, and start jupyter server from terminal with your venv:因此,如果您从 conda 运行 jupyter,则需要将其关闭,然后使用您的 venv 从终端启动 jupyter 服务器:
jupyter notebook
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.