简体   繁体   English

为什么 python 找不到我安装的库?

[英]Why can't python find my installed libaries?

I use python 3.9 and it is no longer able to find the libraries that I have installed libaries even though they are installed.我使用 python 3.9,即使安装了库,它也无法找到我安装的库。

When I for example import pandas I get this message,例如,当我导入 pandas 时,我收到此消息,

>>> import pandas
Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    import pandas
ModuleNotFoundError: No module named 'pandas'

When I use pip to install the library it tells me that it already has been installed.当我使用 pip 安装库时,它告诉我它已经安装了。

C:\Users\malth>pip install pandas
Requirement already satisfied: pandas in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (1.2.3)
Requirement already satisfied: python-dateutil>=2.7.3 in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (from pandas) (2.8.1)
Requirement already satisfied: pytz>=2017.3 in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (from pandas) (2021.1)
Requirement already satisfied: numpy>=1.16.5 in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (from pandas) (1.20.1)
Requirement already satisfied: six>=1.5 in c:\users\malth\appdata\local\programs\python\python39\lib\site-packages (from python-dateutil>=2.7.3->pandas) (1.15.0)

I can even see the library in the site-packages folder.我什至可以在 site-packages 文件夹中看到该库。

Try creating virtual environment, configure it and then install whatever module you require.尝试创建虚拟环境,对其进行配置,然后安装您需要的任何模块。 Its the most easiest way to skip module error anytime.它是随时跳过模块错误的最简单方法。

Try to do pip --version .尝试做pip --version If you have a multiple pythons on your pc, you might have a pip that linked to another version.如果你的电脑上有多个pip pythons I guess you should try to use pyenv or virtualenv .我想你应该尝试使用pyenvvirtualenv This modules allowed you to avoid situation which I described above.这个模块可以让你避免我上面描述的情况。 Also it's a good practice to keep you python env isolated for a specific project.此外,为特定项目隔离 python 环境也是一个好习惯。

As N.Singh has suggested, I would try to set up a new conda environment, adding all possible packages or libraries you will use and then I will make it active.正如 N.Singh 所建议的那样,我会尝试设置一个新的 conda 环境,添加您将使用的所有可能的包或库,然后我会使其处于活动状态。 Information about it can be found here: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment .有关它的信息可以在这里找到: https://conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#activating-an-environment I really hope this helps.我真的希望这会有所帮助。 I have already had the same problem few months ago and worked for me.几个月前我已经遇到了同样的问题并为我工作。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM