简体   繁体   English

Pycharm pip install 不会在代理后面工作

[英]Pycharm pip install wont work behind a proxy

I'm trying to install packages from within Pycharm in Windows 10. I am behind a proxy, so I have set up the proxy information as well as my login details and my connection seems to work.我正在尝试从 Windows 10 中的Pycharm安装包。我在代理后面,所以我设置了代理信息以及我的登录详细信息,我的连接似乎有效。

网络连接

My problem is that both pip and Setup_tools seems fails to connect to the internet and I get the following error after multiple connections retries have failed:我的问题是pipSetup_tools似乎都无法连接到互联网,并且在多次连接重试失败后出现以下错误:

No matching distribution found for [package name]

For example, when I try to install Numpy:例如,当我尝试安装 Numpy 时:

我得到的错误

PS:附言:

  • I have looked at a similar question over here , however I didn't find that helpful.在这里看过一个类似的问题,但是我觉得这没有帮助。

  • I have managed to get pip to work from the command prompt(CMD) after doing the following:执行以下操作后,我设法让 pip 从命令提示符 (CMD) 开始工作:

    1. Export the proxy settings:导出代理设置:

      set http_proxy=http://username:password@proxyAddress:port

      set https_proxy=https://username:password@proxyAddress:port

    2. Install the package:安装包:

      pip install PackageName

For some reason, the following kind of install seem to not work (note this is the same kind of statement Pycharm is trying to use to install my packages):出于某种原因,以下类型的安装似乎不起作用(请注意,这与 Pycharm 试图用来安装我的包的语句类型相同):

pip install --proxy=https://username:password@proxy:port packageName

What am I doing wrong?我究竟做错了什么? How do I resolve this?我该如何解决这个问题? Thanks in advance.提前致谢。

There might be a couple of reasons for your issue.您的问题可能有几个原因。 The first that come to mind are:首先想到的是:

  • did you try to go to Python3 executable path and try the same command from CMD?您是否尝试转到 Python3 可执行路径并从 CMD 尝试相同的命令?

     pip3.exe install --proxy=https://username:password@proxy:port packageName
  • you can also try the same command as above, but a bit changed:您也可以尝试与上面相同的命令,但有一点改变:

     pip3.exe install packageName --proxy=https://username:password@proxy:port
  • are you sure the credentials are ok?你确定凭据没问题吗? (apparently the connection was successfull, I just saw the first image) (显然连接成功了,我只看到了第一张图片)

  • is the proxy up?代理启动了吗? (apparently the connection was successfull, I just saw the first image) (显然连接成功了,我只看到了第一张图片)

I'm using the latter command and it works fine with Python 3.5.x on Windows.我正在使用后一个命令,它在 Windows 上与 Python 3.5.x 一起工作正常。

Create a System Environment Variable HTTPS_PROXY or HTTP_PROXY in windows with required authentication ( https://user:password@proxy:port ) in windows and restart Pycharm.在 windows 中使用所需的身份验证 ( https://user:password@proxy:port ) 在 windows 中创建系统环境变量HTTPS_PROXYHTTP_PROXY并重新启动 Pycharm。

Then, without specifying proxy configuration inside Pycharm, install the package.然后,在 Pycharm 中不指定代理配置,安装包。

This is best solution:这是最好的解决方案:

pip install requests pip 安装请求

If that command is not work in Pycharm , reason is proxy or web filtering and something like this.如果该命令在 Pycharm 中不起作用,原因是代理或网络过滤等。

For fixing this problem you could do these steps:要解决此问题,您可以执行以下步骤:

1. Go to pypi.org 1.前往pypi.org

2. Then find your package ( requests ) 2.然后找到你的包裹(请求)

3. Then in Download section copy.targz link address 3.然后在Download部分copy.targz链接地址

4. In Pycharm terminal type: pip install (your link address that you copied) 4.在Pycharm终端输入: pip install (your link address that you copied)

5. Now press enter, If you will know your package would need some dependencies so 5.现在按回车键,如果你知道你的包需要一些依赖,那么

repeat these steps for dependencies.对依赖项重复这些步骤。

  • Note : Be careful on version of package dependencies that you need to install before install your main package.注意:在安装主包之前,请注意需要安装的包依赖项的版本。

Or you will be able use Proxy with this command:或者您可以通过以下命令使用 Proxy:

pip install --proxy= https://username:password@proxy:port YourPackageName pip install --proxy= https://username:password@proxy:port YourPackageName

In PyCharm you can specify the proxy in the options field in the Available Packages Dialog:在 PyCharm 中,您可以在可用包对话框的选项字段中指定代理:

可用包对话框

This dialog is reachable from the Project Interpreter page by clicking the + button可以通过单击+按钮从项目解释器页面访问此对话框

** **

Fix the pycharm proxy issue in Macbook pro to install libraries behind the corporate proxy:修复 Macbook pro 中的 pycharm 代理问题以在企业代理后面安装库:

** **

go to System settings --> HTTP Proxy转到系统设置 --> HTTP 代理

Select Manual proxy configuration --> HTTP Proxy选择手动代理配置 --> HTTP 代理

  • Host Name: your company hostname --Example.com--主机名:您公司的主机名 --Example.com--

  • port number: specify your corporate proxy --port number--端口号:指定您的公司代理 --port number--

Check Proxy Authentication: Give your system login credentials --> Login and password --> Check Reminder box检查代理身份验证:提供您的系统登录凭据 --> 登录名和密码 --> 检查提醒框

Check the connection: eg: http://www.google.com检查连接:例如: http ://www.google.com

在此处输入图像描述

Now you should be able to download libraries inside the proxy from pycharm.现在您应该能够从 pycharm 下载代理内的库。

If you want to install packages from terminal:如果你想从终端安装包:

pip install --proxy http://username:password@proxy.com:port package-name pip install --proxy http://username:password@proxy.com:port包名

eg: pip install --proxy http://manojnirale:password%40@proxy.com:8080 spacy例如:pip install --proxy http://manojnirale:password%40@proxy.com:8080 spacy

Username:corporate id Password having special characters use Unicode Unicode for @ will be %40.用户名:企业 ID 具有特殊字符的密码使用 Unicode @ 的 Unicode 将为 %40。 Please find the below link for Unicode conversion https://r12a.github.io/app-conversion/请找到以下 Unicode 转换链接https://r12a.github.io/app-conversion/

If you don't want to modify system or user environment variables, proxy address can be passed to PyCharm pip also with this modification of PyCharm Community Edition 2019.3.3.lnk (or another version) in Windows:如果你不想修改系统或用户环境变量,代理地址可以传递给 PyCharm pip 也可以在 Windows 中使用 PyCharm Community Edition 2019.3.3.lnk(或其他版本)的这个修改:

C:\Windows\System32\cmd.exe /c "SET HTTPS_PROXY=http://proxyAddress:port&& START /D ^"C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.3\bin^" pycharm64.exe"

链接设置

make sure to use cert options when installing.确保在安装时使用证书选项。 Path it to a cert.将其指向证书。 that will fill in the correct command that is issued By pycharm New versions of pip break all "pip install" commands这将填写由 pycharm 发出的正确命令 新版本的 pip 中断了所有“pip install”命令

Add these to the options box --cert C:\Users\user_name\certs\ca-certificates.crt --ignore-requires-python将这些添加到选项框 --cert C:\Users\user_name\certs\ca-certificates.crt --ignore-requires-python

在此处输入图像描述

Pycharm 2021.2.1 and Python 3.9.0 installed已安装 Pycharm 2021.2.1 和 Python 3.9.0

After one month of banging my head against the wall trying all the solutions posted on StackOverflow and other websites, I have found my way to solve the problem.在尝试了 StackOverflow 和其他网站上发布的所有解决方案一个月之后,我终于找到了解决问题的方法。 The curious thing was that the proxy was transparent to see all the packages available, but if I tried to install one of them I always had errors answer like:奇怪的是,代理是透明的,可以看到所有可用的包,但如果我尝试安装其中一个,我总是会得到如下错误答案:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken b
y 'ConnectTimeoutError(<pip._vendor.urllib3.connection.HTTPSConnection object at 0x000002861DE54F70>, 'Connection
 to pypi.org timed out. (connect timeout=15)')': /simple/netmiko/

I had tried changing the environment variables, setting the proxy with authentication on pycharm, or trying to execute it from the command line pip install everything , only one solution was missing, the urllib3 install and downgrade but how to do it if you can't take away the proxy server you have behind?我曾尝试更改环境变量,在pip install everything上设置带有身份验证的代理,或尝试urllib3执行它拿走你后面的代理服务器?
I was near to go to the company with a wifi extender to use it as a wifi port to connect to my smartphone like hotspot...... but.我本来打算带着wifi扩展器去公司,把它当作wifi端口,像热点一样连接到我的智能手机……但是。
My company laptop at home was working without a proxy and everything was working fine, I have loaded the urllib3 v1.25.11 on that pc, then I have looked for it into C:\Users\**my.user**\PycharmProjects\pythonProject2\venv\Lib\site-packages\ and I have put the urllib3 and urllibe-1.25.11.dist-info into a zip file and transferred to the pc with the proxy problem in the same place C:\Users\.......venv\Lib\site-packages\我在家里的公司笔记本电脑在没有代理的情况下工作,一切正常,我在那台电脑上加载了urllib3 v1.25.11 ,然后我在C:\Users\**my.user**\PycharmProjects\pythonProject2\venv\Lib\site-packages\中查找它C:\Users\**my.user**\PycharmProjects\pythonProject2\venv\Lib\site-packages\并且我已经将urllib3urllibe-1.25.11.dist-info放入一个 zip 文件中,并在同一个地方C:\Users\.......venv\Lib\site-packages\
I have started pycharm and tried to install urllib v1.25.11 ticking the specified version.我已经启动了 pycharm 并尝试安装urllib v1.25.11勾选指定的版本。 On the first try, it has loaded the last version 1.26.6 , but I have done it again and the installation of urllib3 v1.25.11 was successful.第一次尝试时,它加载了最后一个版本1.26.6 ,但我又做了一次,并且urllib3 v1.25.11安装成功。
Then I have tried to install the other two packages and finally, everything was working as it should.然后我尝试安装其他两个包,最后,一切正常。 I don't know why the people who have made the changes to pip and urllib3 and made it stop working behind a proxy didn't fix it in the next version and they left a lot of people into the shit.我不知道为什么对 pip 和 urllib3 进行更改并使其停止在代理后面工作的人没有在下一个版本中修复它,他们让很多人陷入困境。 Now I can start to work.现在我可以开始工作了。

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

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