Python

※This article is based on Python 3.7.3

pip安装第三方库 [edit]

pip install scikit-learn #下载scikit-learn

只要在下载软件的后面加上==号,写入版本号即可!

pip install 软件名==版本号

# 下载scikit-learn的0.18.0版本

pip install scikit-learn==0.18.0

# 以管理者身份下载scikit-learn的0.18.0版本

pip install --user-v scikit-learn==0.18.0

#将库中的python模块用作脚本去运行安装scikit-learn

python -m pip install scikit-learn

安装pip [edit]

安装python3.x的pip

sudo apt-get install python3-pip

问题 [edit]

pip无法升级 [edit]

报错:

Collecting pip
  Using cached https://files.pythonhosted.org/packages/52/e1/06c018197d8151383f66ebf6979d951995cf495629fc54149491f5d157d0/pip-21.2.4.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\users\tzzha\appdata\local\temp\pip-build-nzbfrv\pip\setup.py", line 7
        def read(rel_path: str) -> str:
                         ^
    SyntaxError: invalid syntax

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\tzzha\appdata\local\temp\pip-build-nzbfrv\pip\
You are using pip version 8.1.2, however version 21.2.4 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

解决

python -m pip install --user --upgrade pip==20.2.4  #(换成你想要的版本编号)

ssl certificate [edit]

WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/virtualenv/

Could not fetch URL https://pypi.org/simple/virtualenv/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/virtualenv/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

或者

Ubuntu urllib2.URLError:<urlopen error unknown url type:https>

原因 [edit]

是因为 Python 不支持 openssl 造成的,需要重新编译安装 python

参考官网

Note HTTPS support is only available if Python was compiled with SSL support (through the ssl module). 

https://docs.python.org/3/library/http.client.html

解决方法 [edit]

先安装 virtualenv

pip install virtualenv -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com

在安装python之前需要先安装 openssl

安装 python 时如下配置、安装

./configure --prefix=/root/python38 --with-openssl=/root/openssl-1.1.0l --enable-shared
make
make install

注意:/root/openssl-1.1.0l路径为openssl官网下载的源码包解压后的文件夹路径

ubuntu WARNING: Download failure <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1131)> [edit]

解决方法 [edit]

sudo update-ca-certificates --fresh
export SSL_CERT_DIR=/etc/ssl/certs

コメント:



(画像の文字列を入力して下さい)

トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS