简体   繁体   English

如何使用 PIP 将包导入 Pycharm?

[英]How to import packages into Pycharm using PIP?

I'm trying to install a package onto Pycharm using PIP. I am running Anacondas on a Pycharm IDE. I know that you use the project interpreter to install packages and I also know that the package should be located under PyPi but when I go to the project interpreter and click add package the package I'm trying to install doesn't appear under the list of available packages.我正在尝试将Pycharm安装到Pycharm上,使用PIP。我正在运行Anacondas,在8835826450388 8IDE中使用Anacondas。项目解释器并单击添加 package 我正在尝试安装的 package 没有出现在可用包列表下。

I know that you can install the package using PIP and I have PIP installed through Anaconda although I am unsure how to run a pip command through Pycharm. I've tried typing it into the cmd console and the python code and neither seems to have any effect... I know that you can install the package using PIP and I have PIP installed through Anaconda although I am unsure how to run a pip command through Pycharm. I've tried typing it into the cmd console and the python code and neither seems to have any影响...

The package I'm trying to install is: https://github.com/seatgeek/fuzzywuzzy .我要安装的 package 是: https://github.com/seatgeek/fuzzywuzzy

The pip command to install it is: pip install fuzzywuzzy but I am unsure as to where I'm supposed to run that command.安装它的 pip 命令是: pip install fuzzywuzzy但我不确定应该在哪里运行该命令。

I'm fairly new at Python so any help would be much appreciated!我是 Python 的新手,非常感谢您的帮助!

Thank you!谢谢!

I found someone else's answer that works for me:我找到了对我有用的其他人的答案

You need to use你需要使用

 import pip pip.main(['install','packagename'])

Which allows you to manually install packages through pip using Python code.这允许您使用 Python 代码通过 pip 手动安装软件包。

This is guide for installing the pip packages from Python Console in Pycharm IDE.这是从 Pycharm IDE 中的 Python 控制台安装 pip 软件包的指南。

Do not forget to run Pycharm as administrator if you are using windows OS before installing the packages.如果您在安装软件包之前使用 windows 操作系统,请不要忘记以管理员身份运行 Pycharm。

First of all import the pacakage of pip in python console.首先在python控制台导入pip的包。

import pip

Installation of Package.安装Package。

 pip.main(['install', '<package_name>'])

Examples例子
The below command will upgrade the version of package setuptools.以下命令将升级 package setuptools 的版本。

pip.main(['install','--upgrade','setuptools'])

The below command will install the scikit-learn and numpy packages.下面的命令将安装 scikit-learn 和 numpy 包。

pip.main(['install','numpy','scikit-learn'])

The below command will uninstall the scikit-learn package.以下命令将卸载 scikit-learn package。

pip.main(['uninstall','scikit-learn'])

Pycharm 中的 Python 控制台快照

I was with the same problem, all i did was: Configure the project interpreter to the Python3 inside the venv you are using the pip install.我遇到了同样的问题,我所做的只是:将项目解释器配置为您正在使用 pip 安装的 venv 中的 Python3。 Remember to activate the venv.记得激活 venv。 That's it, now you can use the pip install on pycharm or on prompot.就是这样,现在您可以在 pycharm 或 prompot 上使用 pip 安装。 The problem is that even with the "venv/lib/sitepackeges" in the your project's sys.path the pycharm looks only for the packages where the project interpreter is.问题是,即使在项目的 sys.path 中使用“venv/lib/sitepackeges”,pycharm 也只会查找项目解释器所在的包。

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

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