简体   繁体   English

Python/Anaconda 无法在 conda 环境中找到已安装的模块

[英]Python/Anaconda can not locate installed modules in conda environments

I am using anaconda as an environment manager for my code.我正在使用 anaconda 作为我的代码的环境管理器。 When i installed anaconda and created the environments everything worked fine.当我安装 anaconda 并创建环境时,一切正常。 But when i came back the next day and activated the environment i keep getting a ModuleNotFoundError但是当我第二天回来并激活环境时,我不断收到ModuleNotFoundError

C:\Users\Username\tutorial>activate raman_37

(raman_37) C:\Users\Username\tutorial>conda list
# packages in environment at C:\Users\Username\.conda\envs\raman_37:
#
# Name                    Version                   Build  Channel
_tflow_select             2.2.0                     eigen
absl-py                   0.9.0                    py37_0
astor                     0.8.0                    py37_0
blas                      1.0                         mkl
blinker                   1.4                      py37_0
ca-certificates           2020.1.1                      0
cachetools                3.1.1                      py_0
certifi                   2020.4.5.1               py37_0
cffi                      1.14.0           py37h7a1dbc1_0
chardet                   3.0.4                 py37_1003
click                     7.1.2                      py_0
configparser              5.0.0                    pypi_0    pypi
cryptography              2.9.2            py37h7a1dbc1_0
docker-pycreds            0.4.0                    pypi_0    pypi
freetype                  2.9.1                ha9979f8_1
gast                      0.2.2                    py37_0
gitdb                     4.0.5                    pypi_0    pypi
gitpython                 3.1.2                    pypi_0    pypi
google-auth               1.14.1                     py_0
google-auth-oauthlib      0.4.1                      py_2
google-pasta              0.2.0                      py_0
gql                       0.2.0                    pypi_0    pypi
graphql-core              1.1                      pypi_0    pypi
grpcio                    1.27.2           py37h351948d_0
h5py                      2.10.0           py37h5e291fa_0
hdf5                      1.10.4               h7ebc959_0
icc_rt                    2019.0.0             h0cc432a_1
idna                      2.9                        py_1
intel-openmp              2020.1                      216
joblib                    0.14.1                     py_0
jpeg                      9b                   hb83a4c4_2
keras                     2.3.1                         0
keras-applications        1.0.8                      py_0
keras-base                2.3.1                    py37_0
keras-preprocessing       1.1.0                      py_1
libpng                    1.6.37               h2a8f88b_0
libprotobuf               3.11.4               h7bd577a_0
libtiff                   4.1.0                h56a325e_0
markdown                  3.1.1                    py37_0
mkl                       2020.1                      216
mkl-service               2.3.0            py37hb782905_0
mkl_fft                   1.0.15           py37h14836fe_0
mkl_random                1.1.0            py37h675688f_0
numpy                     1.18.4                   pypi_0    pypi
nvidia-ml-py3             7.352.0                  pypi_0    pypi
oauthlib                  3.1.0                      py_0
olefile                   0.46                     py37_0
opencv-python             4.2.0.34                 pypi_0    pypi
openssl                   1.1.1g               he774522_0
opt_einsum                3.1.0                      py_0
pandas                    1.0.3            py37h47e9c7a_0
pathtools                 0.1.2                    pypi_0    pypi
pillow                    7.1.2            py37hcc1f983_0
pip                       20.0.2                   py37_3
promise                   2.3                      pypi_0    pypi
protobuf                  3.11.4           py37h33f27b4_0
psutil                    5.7.0                    pypi_0    pypi
pyasn1                    0.4.8                      py_0
pyasn1-modules            0.2.7                      py_0
pycparser                 2.20                       py_0
pyjwt                     1.7.1                    py37_0
pyopenssl                 19.1.0                   py37_0
pypiwin32                 223                      pypi_0    pypi
pyreadline                2.1                      py37_1
pysocks                   1.7.1                    py37_0
python                    3.7.7                h81c818b_4
python-dateutil           2.8.1                      py_0
pytz                      2020.1                     py_0
pywin32                   227                      pypi_0    pypi
pyyaml                    5.3.1            py37he774522_0
requests                  2.23.0                   py37_0
requests-oauthlib         1.3.0                      py_0
rsa                       4.0                        py_0
scikit-learn              0.22.1           py37h6288b17_0
scipy                     1.4.1            py37h9439919_0
sentry-sdk                0.14.4                   pypi_0    pypi
setuptools                46.2.0                   py37_0
shortuuid                 1.0.1                    pypi_0    pypi
six                       1.14.0                   py37_0
smmap                     3.0.4                    pypi_0    pypi
sqlite                    3.31.1               h2a8f88b_1
subprocess32              3.5.4                    pypi_0    pypi
tensorboard               2.1.0                     py3_0
tensorflow                2.1.0           eigen_py37hd727fc0_0
tensorflow-base           2.1.0           eigen_py37h49b2757_0
tensorflow-estimator      2.1.0              pyhd54b08b_0
termcolor                 1.1.0                    py37_1
tk                        8.6.8                hfa6e2cd_0
urllib3                   1.25.8                   py37_0
vc                        14.1                 h0510ff6_4
vs2015_runtime            14.16.27012          hf0eaf9b_1
wandb                     0.8.36                   pypi_0    pypi
watchdog                  0.10.2                   pypi_0    pypi
werkzeug                  0.14.1                   py37_0
wheel                     0.34.2                   py37_0
win_inet_pton             1.1.0                    py37_0
wincertstore              0.2                      py37_0
wrapt                     1.12.1           py37he774522_1
xz                        5.2.5                h62dcd97_0
yaml                      0.1.7                hc54c509_2
zlib                      1.2.11               h62dcd97_4
zstd                      1.3.7                h508b16e_0

(raman_37) C:\Users\Username\tutorial>tutorial.py
Traceback (most recent call last):
  File "C:\Users\Username\tutorial\tutorial.py", line 8, in <module>
    import numpy
ModuleNotFoundError: No module named 'numpy'

I also get the same problem when attempting to run the code outside of an anaconda environment.尝试在 anaconda 环境之外运行代码时,我也遇到了同样的问题。

C:\Users\Username\tutorial>pip install numpy    
Requirement already satisfied: numpy in c:\programdata\anaconda3\lib\site-packages (1.18.1)

C:\Users\Username\tutorial>tutorial.py
Traceback (most recent call last):
  File "C:\Users\Username\tutorial\tutorial.py", line 8, in <module>
    import numpy
ModuleNotFoundError: No module named 'numpy'

When i installed python and anaconda i set both the installers to ADD TO PATH.当我安装 python 和 anaconda 时,我将两个安装程序都设置为添加到路径。

Any help on this would be most appreciated.对此的任何帮助将不胜感激。

This doesn't sound good: "When i installed python and anaconda i set both the installers to ADD TO PATH."这听起来不太好: “当我安装 python 和 anaconda 时,我将两个安装程序都设置为添加到路径。”

  1. Anaconda is a Python distribution. Anaconda 是 Python 分布。 You need this one installer only.您只需要这个安装程序。
  2. Don't add Anaconda's python.exe to the PATH.不要将 Anaconda 的 python.exe 添加到 PATH 中。 This is not how environments work.这不是环境的工作方式。
  3. If you want to work with Anaconda, you need to activate at least the base environment using the 'conda' environment manager.如果您想使用 Anaconda,您至少需要使用“conda”环境管理器激活基本环境。 This is how Python can find eg numpy's C-libraries.这就是 Python 可以找到例如 numpy 的 C 库的方式。
  4. You can install Python from python.org in parallel to Anaconda, but this is asking for trouble.您可以从 python.org 与 Anaconda 并行安装 Python,但这是自找麻烦。

On Windows 10: I had the same problem after installing packages to a given anaconda environment, the package that I confirmed was installed after running conda list would be reported as "no module named databases" for instance.在 Windows 10 上:将软件包安装到给定的 anaconda 环境后,我遇到了同样的问题,我确认在运行 conda list 后安装了名为实例数据库的模块的 package 将报告为“no” It was because I was simply typing the *.py file at the command line and not 'python *.py'.这是因为我只是在命令行输入 *.py 文件而不是“python *.py”。 Running the *.py file from the command line was the problem.从命令行运行 *.py 文件是问题所在。 I needed to include the python statement before the *.py.我需要在 *.py 之前包含 python 语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 合并多个Anaconda环境(无意中创建了第二个,安装了几个模块) - Merge multiple Anaconda environments (accidentally created a second, and installed several modules) 默认的python不会找到随自制软件安装的模块 - default python does not locate modules installed with homebrew 在不同环境下运行时,无法导入Anaconda 2中安装的库 - Can not import library installed in Anaconda 2 while operating with different environments 如何将Python环境添加到给定文件/模块的路径conda / anaconda - How to add a Python Environment to path given files/modules conda/anaconda Conda 看不到已安装的模块 - Conda not seeing installed modules 使用Conda管理Python环境 - Managing Python Environments With Conda 在我安装 anaconda 后没有新的 pip 安装的模块可以导入 - after I installed anaconda no new pip installed modules can be imported 如何将安装在anaconda上的模块与不同的python版本共享? - How to share modules installed on anaconda with different python versions? 为什么安装在 python 目录下的模块无法识别,但anaconda3 下的模块可以识别? - Why are modules installed in python directory not recognised but those under anaconda3 are? 定义将安装在所有新 conda 环境中的软件包 - Define packages that will be installed in all new conda environments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM