简体   繁体   English

Pycharm在windows上找不到pip安装的包或模块

[英]Pycharm cann't find the packages or modules installed with pip on windows

Pycharm doesn't sync with the pip packages though i have added the path in environment variable.尽管我在环境变量中添加了路径,但 Pycharm 不与 pip 包同步。 The following elements will clear the topic:以下元素将清除主题:

already installed sklearn package:已经安装了 sklearn 包: 在此处输入图片说明

pycharm can't find that package: pycharm 找不到那个包:

在此处输入图片说明

environment variable:环境变量:

https://i.stack.imgur.com/1zehq.png

Seems like the interpreter selected isn't where you think it is.似乎所选的口译员不在您认为的位置。 If you're using a different interpreter than the system's default, it won't load the modules.如果您使用的解释器与系统默认解释器不同,则它不会加载模块。 To add the modules in PyCharm, go to your Settings, Project Interpreter, the Add Button, and install it with PyCharm's integrated package management.要在 PyCharm 中添加模块,请转到您的设置、项目解释器、添加按钮,并使用 PyCharm 的集成包管理进行安装。

脚步

The thing is that pycharm creates all of your projects inside a virtual environment.问题是 pycharm 在虚拟环境中创建您的所有项目。 So the packages that you installed outside the virtual environment(global site packages) does not get inherited in to your project.因此,您在虚拟环境之外安装的包(全局站点包)不会继承到您的项目中。 There is a simple solution for that.有一个简单的解决方案。 When you create a pycharm project, make sure to check the "inherit global-site packages" checkbox as shown here.Then you'll be able to import all the packages to your virtual environment, provided they have been installed in your computer.创建 pycharm 项目时,请确保选中“继承全局站点包”复选框,如下所示。然后您将能够将所有包导入到您的虚拟环境中,前提是它们已安装在您的计算机中。

在此处输入图片说明

Alternatively you can install all the packages separately using "pip install" in the pycharm terminal .或者,您可以在pycharm 终端中使用“pip install”单独安装所有软件包。 If the package has been installed outside the virtual environment, pip will use cached files instead of downloading the package again.如果包已经安装在虚拟环境之外,pip 将使用缓存文件而不是再次下载包。

Or you can install the packages using Settings -> Project -> Project Interpreter as the other answers suggests.或者您可以按照其他答案的建议使用Settings -> Project -> Project Interpreter安装软件包。

In PyCharm, go to File / Default Settings / Project Interpreter在 PyCharm 中,转到文件/默认设置/项目解释器

On that page there is a plus in the bottom left, whatever modules you have installed through pip you may need to manually install there.在该页面的左下角有一个加号,您可能需要手动安装通过 pip 安装的任何模块。 Or you can change your project interpreter to make sure you are using the correct interpreter with all your installed modules.或者,您可以更改项目解释器,以确保对所有安装的模块使用正确的解释器。

If you did not "inherit global-site packages" upon creating the project, check in the project tree under External Libaries , if the folder is marked in red.如果您在创建项目时没有“继承全局站点包” ,请检查External Libaries下的项目树,如果文件夹标记为红色。 Ie if you do not use the systems default interpreter , Lib/site-packages could be marked in red.即,如果您不使用系统默认解释器,则 Lib/site-packages 可能会标记为红色。 To add those libraries afterwards, go to: File-Project(your project)\\Project Structure , select +Add Content Root , browse to site-packages (or the respective folder you want to add), and add it.之后要添加这些库,请转到: File-Project(your project)\\Project Structure ,选择+Add Content Root ,浏览到站点包(或要添加的相应文件夹),然后添加它。 After clicking OK the folder will not be marked red any longer.单击“确定”后,该文件夹将不再标记为红色。 (tested in PyCharm 2020.3) (在 PyCharm 2020.3 中测试)

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

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