多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
官网: https://github.com/pyenv/pyenv 功能: 管理Python解释器 管理Python版本 管理python的虚拟环境 安装步骤 1)创建www用户,使用www用户登录系统 [root@python ~]# useradd www && echo "Aa123456" | passwd --stdin www [root@python ~]# su - www 2)安装依赖包 [www@python ~]$ sudo yum -y install git gcc make patch gdbm-devel openssl-devel sqlite-devel readline-devel zlib-devel bzip-devel 3)安装pyenv [www@python ~]$ sudo curl -L https://raw.githubusercontent.com/pyenv/pyenv-installer/master/bin/pyenv-installer | bash export PATH="/home/www/.pyenv/bin:$PATH" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)" 4)添加~/.bash_profile [www@python ~]$ sudo vim /home/www/.bash_profile export PATH="/home/www/.pyenv/bin:$PATH" eval "$(pyenv init -)" eval "$(pyenv virtualenv-init -)" [www@python ~]$ source /home/www/.bash_profile 二)pyenv简单使用 1)查看可以安装哪里版本 [www@python ~]$ pyenv install -l 2)安装某个版本 [www@python ~]$ pyenv install 3.5.3 第二种方法: [www@python ~]$ cd .pyenv/ [www@python .pyenv]$ mkdir cache 然后把下载的包(3.5.3),放到cache目录里 然后执行 pyenv install 3.5.3 然后执行 pyenv install 3.6.1 global Set or show the global Python version (影响所有的,一般情况不用) [www@python ~]$ pyenv version system (set by /home/www/.pyenv/version) [www@python ~]$ pyenv global 3.5.3 [www@python ~]$ pyenv version 3.5.3 (set by /home/www/.pyenv/version) shell Set or show the shell-specific Python version (把当前shell环境改成3.5.3,是会话级别的,一般也不用) [www@python ~]$ pyenv shell 3.5.3 [www@python ~]$ pyenv version 3.5.3 (set by PYENV_VERSION environment variable) [www@python ~]$ cd python_syntax/project/ [www@python project]$ ll total 0 [www@python project]$ pyenv local 3.5.3 [www@python project]$ pyenv version 3.5.3 (set by /home/www/python_syntax/project/.python-version) [www@python project]$ cd .. (在其他目录下,显示python版本) [www@python python_syntax]$ pyenv version system (set by /home/www/.pyenv/version) [www@python python_syntax]$ cd project/ [www@python project]$ mkdir syntax (在当前目录的子目录下,显示python版本) [www@python project]$ cd syntax/ [www@python syntax]$ pyenv version 3.5.3 (set by /home/www/python_syntax/project/.python-version) (在指定目录以及子目录下,使用指定的python版本,其他目录使用别的版本) 使用虚拟环境 Virtualenv插件 plugins/pyenv-virtualenv 创建出一个3.5.3版本的独立空间 [www@python syntax]$ pwd /home/www/python_syntax/project/syntax [www@python syntax]$ pyenv virtualenv 3.5.3 yuki353 Requirement already satisfied: setuptools in /home/www/.pyenv/versions/3.5.3/envs/yuki353/lib/python3.5/site-packages Requirement already satisfied: pip in /home/www/.pyenv/versions/3.5.3/envs/yuki353/lib/python3.5/site-packages [www@python syntax]$ pyenv versions * system (set by /home/www/python_syntax/project/.python-version) 3.5.3 3.5.3/envs/yuki353 3.6.1 yuki353 [www@python syntax]$ pyenv local yuki353 (yuki353) [www@python syntax]$ 二)pip的安装 [www@python ~]$ mkdir .pip [www@python ~]$ vim ~/.pip/pip.conf [global] index-url=https://mirrors.aliyun.com/pypi/simple/ trusted-host=mirrors.aliyun.com ~ [www@python ~]$ cd python_syntax/project/syntax/ (yuki353) [www@python syntax]$ pip -V pip 9.0.1 from /home/www/.pyenv/versions/3.5.3/envs/yuki353/lib/python3.5/site-packages (python 3.5) 安装ipython (yuki353) [www@python syntax]$ pip install ipython 查看安装的包存放位置 [www@python site-packages]$ pwd /home/www/.pyenv/versions/3.5.3/envs/yuki353/lib/python3.5/site-packages [www@python site-packages]$ ll|grep pip drwxrwxr-x. 11 www www 4096 Jan 22 11:49 pip drwxrwxr-x. 2 www www 155 Jan 22 11:49 pip-9.0.1.dist-info (yuki353) [www@python syntax]$ pip install jupyter (yuki353) [www@python syntax]$ jupyter notebook password Enter password: Verify password: [NotebookPasswordApp] Wrote hashed password to /home/www/.jupyter/jupyter_notebook_config.json (yuki353) [www@python syntax]$ jupyter notebook --ip=0.0.0.0 --no-browser [I 13:07:42.212 NotebookApp] Writing notebook server cookie secret to /run/user/1000/jupyter/notebook_cookie_secret [I 13:07:42.947 NotebookApp] Serving notebooks from local directory: /home/www/python_syntax/project/syntax [I 13:07:42.947 NotebookApp] 0 active kernels [I 13:07:42.947 NotebookApp] The Jupyter Notebook is running at: [I 13:07:42.947 NotebookApp] http://0.0.0.0:8888/ [I 13:07:42.947 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). 使用浏览器访问 ![](https://box.kancloud.cn/8f0b2477d7827493a5ec050d9c7ca834_1131x284.png) 把安装的包导出来 (yuki353) [www@python syntax]$ pip freeze > /tmp/packages.txt 然后在另一个虚拟环境,把包导入进去 (wangbin353) [www@python syntax]$ pip install -r /tmp/packages.txt (注意:最好在同一个python版本下导出导入,不建议跨版本(python)使用)