PYTHON配置环境变量无效?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PYTHON配置环境变量无效?相关的知识,希望对你有一定的参考价值。

见下图,明明已经配置了,而且安装时选择了添加到环境中,path也添加了相应路径,就是不成功

将其设置为默认python,可选
cmd命令打开vi ~/.bash_profile进行修改
# Setting PATH for Python 3.6
# The original version is saved in .bash_profile.pysave
# PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:$PATH"
PATH="/usr/local/bin:$PATH"
export PATH
PATH=”/usr/local/Cellar/python/3.6.4_4/bin:$PATH”
export PATH
alias python="/usr/local/Cellar/python/3.6.4_4/bin/python3.6"

cmd命令:
source ~/.bash_profile
添加zsh配置文件:
HenrydeMacBook% vim ~/.zshrc
HenrydeMacBook% cat ~/.zshrc
source ~/.bash_profile
参考技术A 我答题显示不出来?

环境变量`no_proxy`对`setup.py upload`无效

我正在尝试将python工件上传到位于我公司网络上的自定义nexus存储库,但它不起作用:

$ python2 setup.py bdist_wheel --universal upload -r nexus
running bdist_wheel
running build
running build_py
running build_scripts
installing to build/bdist.linux-x86_64/wheel
running install
running install_lib
creating build/bdist.linux-x86_64/wheel
. . .
. . .
. . .
running upload
Submitting /home/<user>/dist/processing_catalog-0.1.1-py2.py3-none-any.whl to http://nexus3.mycompany.net/repository/pip/
Upload failed (503): Service Unavailable
error: Upload failed (503): Service Unavailable

我是企业HTTP代理(10.200.1.1:3128)的幕后推手。但是,nexus存储库位于同一网络中,因此我对公司本地域“无代理”。这是我的代理环境变量:

$ env | grep -Fi proxy
NO_PROXY=localhost,127.0.0.0/8,::1,.mycompany.net
http_proxy=http://10.200.1.1:3128
https_proxy=http://10.200.1.1:3128
HTTPS_PROXY=http://http://10.200.1.1:3128/
no_proxy=localhost,127.0.0.1,.mycompany.net
HTTP_PROXY=http://http://10.200.1.1:3128/

执行upload命令时tcpdump显示流程发送到代理:

$ sudo tcpdump -Q out -i eth0 -nn dst host 10.200.1.1 and dst port 3128
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
11:36:58.537988 IP 10.100.59.19.38048 > 10.200.1.1.3128: Flags [S], seq 3601157597, win 29200, options [mss 1460,sackOK,TS val 1913260691 ecr 0,nop,wscale 7], length 0
11:36:58.539684 IP 10.100.59.19.38048 > 10.200.1.1.3128: Flags [.], ack 3499932568, win 229, options [nop,nop,TS val 1913260692 ecr 2310337451], length 0
11:36:58.539746 IP 10.100.59.19.38048 > 10.200.1.1.3128: Flags [.], seq 0:7240, ack 1, win 229, options [nop,nop,TS val 1913260692 ecr 2310337451], length 7240
11:36:58.539753 IP 10.100.59.19.38048 > 10.200.1.1.3128: Flags [.], seq 7240:14480, ack 1, win 229, options [nop,nop,TS val 1913260692 ecr 2310337451], length 7240
11:36:58.542743 IP 10.100.59.19.38048 > 10.200.1.1.3128: Flags [P.], seq 14480:16847, ack 1, win 229, options [nop,nop,TS val 1913260695 ecr 2310337454], length 2367
11:36:58.567501 IP 10.100.59.19.38048 > 10.200.1.1.3128: Flags [.], ack 4009, win 291, options [nop,nop,TS val 1913260720 ecr 2310337476], length 0
11:36:58.567866 IP 10.100.59.19.38048 > 10.200.1.1.3128: Flags [F.], seq 16847, ack 4010, win 291, options [nop,nop,TS val 1913260721 ecr 2310337476], length 0
^C
7 packets captured
7 packets received by filter
0 packets dropped by kernel

这很好地说明了在执行上传时nexus服务器端没有收到日志这一事实。

我的上传配置:

$ cat ~/.pypirc
[distutils]
index-servers =
    nexus

[nexus]
repository: http://nexus3.mycompany.net/repository/pip/
username:
password:

$ sudo cat /etc/pip.conf
[global]
timeout = 60
trusted-host = pypi.python.org
               nexus3.mycompany.net
index-url = https://pypi.python.org/simple
extra-index-url = http://nexus3.mycompany.net/repository/pip/simple

另一方面,一个点子下载工作正常:

$ pip download processing-catalog
Collecting processing-catalog
  Downloading http://nexus3.mycompany.net/repository/pip/packages/processing-catalog/0.1.2/processing_catalog-0.1.2-py2.py3-none-any.whl
. . .
. . .
. . .
Successfully downloaded processing-catalog . . .

同样适用于简单的卷曲:

$ curl -sv -u <username>:<password> http://nexus3.mycompany.net/repository/pip/packages/processing-catalog/0.1.1/processing_catalog-0.1.1-py2.py3-none-any.whl -o processing_catalog-0.1.1-py2.py3-none-any.whl
*   Trying 10.100.58.110...
* Connected to nexus3.mycompany.net (10.100.58.110) port 80 (#0)
* Server auth using Basic with user '<username>'
> GET /repository/pip/packages/processing-catalog/0.1.1/processing_catalog-0.1.1-py2.py3-none-any.whl HTTP/1.1
> Host: nexus3.mycompany.net
> Authorization: Basic <token>
> User-Agent: curl/7.47.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< Date: Tue, 27 Feb 2018 10:51:47 GMT
< Server: Nexus/3.6.2-01 (OSS)
< X-Frame-Options: SAMEORIGIN
< X-Content-Type-Options: nosniff
< Last-Modified: Tue, 27 Feb 2018 10:11:01 GMT
< Content-Type: application/zip
< Content-Length: 14229
< 
{ [4096 bytes data]
* Connection #0 to host nexus3.mycompany.net left intact

那么,为什么setup.py upload会在代理上出去?

答案

回答我自己的问题

我认为,与curlpip不同,setup.py upload无法在no_proxy环境变量中读取域格式,并在开头使用.。看到:


.变量的域开头没有no_proxy:它有效

$ no_proxy=mycompany.net python2 setup.py bdist_wheel --universal upload -r nexus
running bdist_wheel
running build
running build_py
running build_scripts
installing to build/bdist.linux-x86_64/wheel
running install
running install_lib
creating build/bdist.linux-x86_64/wheel
creating build/bdist.linux-x86_64/wheel/processing_catalog
. . .
. . .
. . .
running upload
Submitting /home/<user>/dist/processing_catalog-0.1.1-py2.py3-none-any.whl to http://nexus3.mycompany.net/repository/pip/
Server response (200): OK

.no_proxy变量域的开头:它不起作用

$ no_proxy=.mycompany.net python2 setup.py bdist_wheel --universal upload -r nexus
running bdist_wheel
running build
running build_py
running build_scripts
installing to build/bdist.linux-x86_64/wheel
running install
running install_lib
creating build/bdist.linux-x86_64/wheel
creating build/bdist.linux-x86_64/wheel/processing_catalog
. . .
. . .
. . .
running upload
Submitting /home/<user>/dist/processing_catalog-0.1.1-py2.py3-none-any.whl to http://nexus3.mycompany.net/repository/pip/
Upload failed (503): Service Unavailable
error: Upload failed (503): Service Unavailable

以上是关于PYTHON配置环境变量无效?的主要内容,如果未能解决你的问题,请参考以下文章

关于pycharm社区版环境配置

python需要配置环境变量吗

window怎么配置python环境变量

解决mac配置maven环境变量成功,关闭终端再次启动终端maven无效问题

python环境变量设置 需要把python的环境配置好

pycharm配置环境变量