centOS7安裝python3.6.5&python3創建虛擬環境教程

1、下載Python-3.6.5安裝包

  • 在Python官網https://www.python.org/dowmloads/下載對應的安裝包,選擇3.6.5對應的linux版本

2、將安裝包上傳至Linux服務器

  • 在Linux服務器根目錄下創建目錄soft,並將安裝包上傳至該目錄下

3、解壓Python-3.6.5.tgz

  • [root@Cherry /]# cd /soft/
  • [root@Cherry soft]# tar -zxvf Python-3.6.5.tgz

4、創建Python-3.6.5安裝目錄

  • [root@Cherry soft]# mkdir /usr/local/python3

5、安裝依賴包

  • [root@Cherry soft]# yum install -y gcc
  • [root@Cherry soft]# yum install -y zlib*
  • [root@Cherry soft]# yum install openssl openssl-devel
  • [root@Cherry soft]# yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

6、配置安裝路徑

  • [root@Cherry soft]# cd Python-3.6.5
  • [root@Cherry Python-3.6.5]# ./configure --prefix=/python3 注意這裏一定要配置絕對路徑

7、編譯

  • [root@Cherry Python-3.6.5]# make

8、安裝

  • [root@Cherry Python-3.6.5]# make install

9、建立軟連接

  • [root@localhost Python-3.6.5]# ln -s /python3.6.5/bin/python3 /usr/bin/python3
  • [root@localhost Python-3.6.5]# ln -s /python3.6.5/bin/pip3 /usr/bin/pip3

10、增加環境變量

  • 修改配置文件:vi /etc/profile,增加以下內容並保存:
  • export PYTHON_HOME=/python3 (這是安裝路徑)
  • export PATH=PYTHONHOME/bin:PYTHON_HOME/bin:PATH (這裏直接copy)
  • 執行語句source /etc/profile使環境變量配置立即生效

11、測試是否安裝成功

  • [root@localhost Python-3.6.5]# python3
Python 3.6.5 (default, Oct 30 2019, 10:13:28) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 

12、測試pip3是否可用

  • [root@localhost Python-3.6.5]# pip3

Usage:   
  pip <command> [options]

Commands:
  install                     Install packages.
  download                    Download packages.
  uninstall                   Uninstall packages.
  freeze                      Output installed packages in requirements format.
  list                        List installed packages.
  show                        Show information about installed packages.
  check                       Verify installed packages have compatible dependencies.
  search                      Search PyPI for packages.
  wheel                       Build wheels from your requirements.
  hash                        Compute hashes of package archives.
  completion                  A helper command used for command completion.
  help                        Show help for commands.

General Options:
  -h, --help                  Show help.
  --isolated                  Run pip in an isolated mode, ignoring environment variables and user configuration.
  -v, --verbose               Give more output. Option is additive, and can be used up to 3 times.
  -V, --version               Show version and exit.
  -q, --quiet                 Give less output. Option is additive, and can be used up to 3 times (corresponding to WARNING, ERROR, and CRITICAL logging levels).
  --log <path>                Path to a verbose appending log.
  --proxy <proxy>             Specify a proxy in the form [user:passwd@]proxy.server:port.
  --retries <retries>         Maximum number of retries each connection should attempt (default 5 times).
  --timeout <sec>             Set the socket timeout (default 15 seconds).
  --exists-action <action>    Default action when a path already exists: (s)witch, (i)gnore, (w)ipe, (b)ackup, (a)bort.
  --trusted-host <hostname>   Mark this host as trusted, even though it does not have valid or any HTTPS.
  --cert <path>               Path to alternate CA bundle.
  --client-cert <path>        Path to SSL client certificate, a single file containing the private key and the certificate in PEM format.
  --cache-dir <dir>           Store the cache data in <dir>.
  --no-cache-dir              Disable the cache.
  --disable-pip-version-check
                              Don't periodically check PyPI to determine whether a new version of pip is available for download. Implied with --no-index.

13、linux環境python3創建虛擬環境

  • 創建虛擬環境目錄:python3 -m venv venv-python365 venv-python365爲目錄名,自定義即可
  • 激活虛擬環境:source venv-python365/bin/activate
  • 退出虛擬環境:deactivate

14、windows環境python3創建虛擬環境

  • 創建虛擬環境目錄:python3 -m venv venv-python365 venv-python365爲目錄名,自定義即可
  • 激活虛擬環境:進入到venv-python365/scripts,然後執行activate,即可進入虛擬環境
  • 退出虛擬環境:deactivate
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章