[英]Module is not found when trying to import it and running a virtual environment (venv)
我目前正在使用 python 的虛擬環境 (venv)。按照標准約定,“venv”目錄位於我的項目文件夾中。
我的項目文件夾包含多個不同的模塊。
我有一個 jupyter notebook,開頭有多個 import 語句。 其中一個導入語句調用我的其他定制模塊之一。 這個特定模塊導入 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
但是,當我嘗試導入包含 tensorflow 的模塊時,我得到ModuleNotFoundError: No module named 'tensorflow'
。 我們可以清楚的看到tensorflow已經被pip3安裝好了。 我這里有什么問題?
我是一般編程的新手,希望能在這里得到一些指導。 我查看了 PYTHONPATH 變量並試圖理解它。 我也對此感到困惑,因為我在這里實現了一個虛擬環境。 我正在使用 MacOS。
您可能正在從不同的虛擬環境運行您的 jupyter notebook。 因此,如果您從 conda 運行 jupyter,則需要將其關閉,然后使用您的 venv 從終端啟動 jupyter 服務器:
jupyter notebook
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.