Installation Python3
Download Source python3
1.cd /opt
2.wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz
3. Install the library before python3 environment or else behind the various pit installation library
1 yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
1 Note: Sometimes error process is locked yum, yum attention only during the installation process only a 2 3 PS -ef | grep yum 4 5 in kill it wants to kill
4. The decompressor
1 tar -xvf Python-3.7.0.tgz
5. Compile and install
1. Release the compiled file makefile, is used to compile the installation
1 ./configure --prefix=/opt/python37/
--Prefix specifies the software installation path
2. Run the make command to compile such a long wait slowly
3. Compile and run make install to install files generated python37
Configuring the environmental variables python3.7
1. Configure the soft link ln -s soft target file connection file
1 ln -s /opt/python37/bin/python3.7 /usr/bin/python3
1 ln -s /opt/python37/bin/pip3 /usr/bin/pip3
2. Configure the path environment variable (to use the good point because it is installed behind pip3)
Check environment variable: echo $ PATH
1 /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
. 1 the PATH = / usr / local / sbin: / usr / local / bin: / usr / sbin: / usr / bin: / the root / bin: / opt / python37 / bin 2 . 3 # in / etc / profile the last row was added 4 # Export the PATH = $ the PATH: / opt / python37 / bin . 5 # and source / etc / profile
Installing the Virtual Environment
1. Install virtualenv
1 pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple virtualenv
2. Create a virtual directory environment
1 mkdir myenv 2 3 cd myenv/
3. Create a stand-alone environment
. 1 the virtualenv --no-Site-python3 Venv Packages - Python = # give environment independent third party package, and specifies the interpreter is python3
4. Then read activate ---> activation
5.deactivate ---> Exit
6. In fact, you can test yourself at first to open two projects run directly out of my
Contrast change environment variables:
Ensure environmental consistency
1 Solution: 2 1 By order ensure the consistency of the environment, the export package python current environment 3 PIP3 Freeze> requirements.txt 4 5 This will create a requirements.txt file, which contains all of the current environment and each package the simple version of the list. 6 can use the "pip list" in case of no requirements document, see the list of packages installed. . 7 . 8 . 9 2 . Once uploaded to the server, the server creates at virtualenv import modules required items in dependence on venv 10 PIP3 the install -R & lt requirements.txt
Install virtual environment management tool virtualenvwrapper
1 # 安装这个命令 必须在物理解释器底下。 2 [root@localhost myenv]# pip3 install virtualenvwrapper
1 pip3 install -i http://pypi.douban.com/simple virtualenvwrapper --trusted-host pypi.douban.com
设置linux环境变量,每次开机自动加载这个工具
export读取shell变量的作用
1 编辑 ~/.bashrc文件 2 打开文件 3 vim ~/.bashrc 4 写入以下两行代码 5 export WORKON_HOME=~/Envs #设置virtualenv的统一管理目录 6 export VIRTUALENVWRAPPER_VIRTUALENV_ARGS='--no-site-packages' #添加virtualenvwrapper的参数,生成干净隔绝的环境 7 export VIRTUALENVWRAPPER_PYTHON=/opt/python37/bin/python3 #指定python解释器 8 source /opt/python37/bin/virtualenvwrapper.sh #执行virtualenvwrapper安装脚本 9 读取文件,使得生效,此时已经可以使用virtalenvwrapper 10 source ~/.bashrc
配置完就可以看到家目录Envs
创建虚拟环境
1 mkvirtualenv prodenv
查看虚拟环境有哪些
1 workon
直接激活环境
1 workon prodenv
其它命令
1 rmvirtualenv prodenv 2 删除虚拟环境 3 4 lsvirtualenv 5 列举所有的环境。 6 7 cdvirtualenv 8 导航到当前激活的虚拟环境的目录中,比如说这样您就能够浏览它的 site-packages 。 9 10 cdsitepackages 11 和上面的类似,但是是直接进入到 site-packages 目录中。 12 13 lssitepackages 14 显示 site-packages 目录中的内容。 15 16 完整官网介绍:https://virtualenvwrapper.readthedocs.io/en/latest/command_ref.html
之后我发现一个问题再次创建虚拟环境的时候就报错了,报错信息
解决:我这是centos7的解决方式
更新pip: 这是pip多版本造成的
1 python3 -m pip install -U pip
为了确保万一我又从新试了下:搞定