1. 程式人生 > >Python3安裝與配置venv虛擬環境

Python3安裝與配置venv虛擬環境

Python3安裝與配置venv虛擬環境

建立安裝目錄

mkdir -p /usr/local/python3  &&
cd /usr/local/python3/

下載適宜的版本(傳送門)

wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz

解壓

tar -vzxf Python-3.6.6.tgz && cd Python-3.6.6

config

./configure --prefix=/usr/local/python3/Python-3.6.6

安裝

make  &&  make install

配置Python3軟連線

ln -s /usr/local/python3/Python-3.6.6/bin/python3.6 /usr/bin/python3
ln
-s /usr/local/python3/Python-3.6.6/bin/pip3 /usr/bin/pip3

驗證python3環境

[[email protected] bin]# python3
Python 3.6.6 (default, Nov 14 2018, 18:41:59) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

升級 pip

#-i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com 指定使用阿里雲的源,可以不加
pip3 install --upgrade pip -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

安裝venv

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

建立程式碼目錄

mkdir -p /data/code/python && cd  /data/code/python

建立venv虛擬工作環境

python3 -m venv /data/code/python/venv_proxy_pool

檢視 venv虛擬環境

[[email protected] venv_proxy_pool]# ls -l
總用量 16
drwxr-xr-x 2 root root 4096 11月 14 19:08 bin
drwxr-xr-x 2 root root 4096 11月 14 19:08 include
drwxr-xr-x 3 root root 4096 11月 14 19:08 lib
lrwxrwxrwx 1 root root    3 11月 14 19:08 lib64 -> lib
-rw-r--r-- 1 root root   69 11月 14 19:08 pyvenv.cfg

拉程式碼

cd /data/code/python/venv_proxy_pool/
git clone  https://github.com/jhao104/proxy_pool.git

升級venv pip3

/data/code/python/venv_proxy_pool/bin/pip3 install --upgrade pip -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

安裝環境依賴

/data/code/python/venv_proxy_pool/bin/pip3 install -r /data/code/python/venv_proxy_pool/proxy_pool/requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

執行

cd /data/code/python/venv_proxy_pool/proxy_pool/Run/
/data/code/python/venv_proxy_pool/bin/python3 main.py