CentOS下搭建个人Python开发环境
来源:互联网 发布:xy网络流行什么意思 编辑:程序博客网 时间:2024/04/26 07:04
环境如下:
搭建步骤:
1、下载Python源码包,附上官网下载链接:https://www.python.org/downloads/。
[lucy@min software]$ lsPython-3.5.2.tgz # 下面以安装Python-3.5.2.tgz为例
2、解压Python-3.5.2.tgz。
[lucy@min software]$ tar xf Python-3.5.2.tgz [lucy@min software]$ lsPython-3.5.2 Python-3.5.2.tgz
3、编译安装Python-3.5.2到/home/lucy/python352下。
[lucy@min Python-3.5.2]$ ./configure --prefix=/home/lucy/python352checking build system type... x86_64-unknown-linux-gnuchecking host system type... x86_64-unknown-linux-gnuchecking for --enable-universalsdk... nochecking for --with-universal-archs... nochecking MACHDEP... linuxchecking for --without-gcc... nochecking for --with-icc... nochecking for gcc... nochecking for cc... nochecking for cl.exe... noconfigure: error: in `/home/lucy/software/Python-3.5.2':configure: error: no acceptable C compiler found in $PATHSee `config.log' for more details
configure时报错“no acceptable C compiler found in $PATH”,在环境变量$PATH下没找到可用的C编译器,安装GCC编译器便可解决。
[lucy@min Python-3.5.2]$ su - rootPassword:[root@min ~]# yum install gcc -y
重新编译安装Python-3.5.2:
[lucy@min Python-3.5.2]$ ./configure --prefix=/home/lucy/python352[lucy@min Python-3.5.2]$ make[lucy@min Python-3.5.2]$ make install......Ignoring ensurepip failure: pip 8.1.1 requires SSL/TLS
make install到最后提示“failure:pip 8.1.1 requires SSL/TLS”,在安装编译Python-3.5.2时默认也会安装pip,但pip依赖于SSL/TLS,故得先安装openssh-devel。
[lucy@min Python-3.5.2]$ su - rootPassword:[root@min ~]# yum install openssl-devel -y重新"make install":[root@min ~]# exit[lucy@min Python-3.5.2]$ make install......Successfully installed pip-8.1.1 setuptools-20.10.1[lucy@min python352]$ lsbin include lib share[lucy@min python352]$ ls bin/total 24032lrwxrwxrwx 1 lucy lucy 8 Aug 16 22:28 2to3 -> 2to3-3.5-rwxrwxr-x 1 lucy lucy 111 Aug 16 22:28 2to3-3.5-rwxrwxr-x 1 lucy lucy 251 Aug 16 22:29 easy_install-3.5lrwxrwxrwx 1 lucy lucy 7 Aug 16 22:28 idle3 -> idle3.5-rwxrwxr-x 1 lucy lucy 109 Aug 16 22:28 idle3.5-rwxrwxr-x 1 lucy lucy 223 Aug 16 22:29 pip3-rwxrwxr-x 1 lucy lucy 223 Aug 16 22:29 pip3.5lrwxrwxrwx 1 lucy lucy 8 Aug 16 22:28 pydoc3 -> pydoc3.5-rwxrwxr-x 1 lucy lucy 94 Aug 16 22:28 pydoc3.5lrwxrwxrwx 1 lucy lucy 9 Aug 16 22:28 python3 -> python3.5-rwxr-xr-x 2 lucy lucy 12284743 Aug 16 22:26 python3.5lrwxrwxrwx 1 lucy lucy 17 Aug 16 22:28 python3.5-config -> python3.5m-config-rwxr-xr-x 2 lucy lucy 12284743 Aug 16 22:26 python3.5m-rwxr-xr-x 1 lucy lucy 3090 Aug 16 22:28 python3.5m-configlrwxrwxrwx 1 lucy lucy 16 Aug 16 22:28 python3-config -> python3.5-configlrwxrwxrwx 1 lucy lucy 10 Aug 16 22:28 pyvenv -> pyvenv-3.5-rwxrwxr-x 1 lucy lucy 246 Aug 16 22:28 pyvenv-3.5
4、安装virtualenvwrapper。
[lucy@min bin]$ ./pip3 install virtualenvwrapperCollecting virtualenvwrapper......Successfully installed pbr-1.10.0 six-1.10.0 stevedore-1.17.0 virtualenv-15.0.3 virtualenv-clone-0.2.6 virtualenvwrapper-4.7.1[lucy@min bin]$ ls -l virtualenvwrapper.sh -rwxrwxr-x 1 lucy lucy 41384 Aug 16 22:46 virtualenvwrapper.sh
安装完成后会在当前目录下生成virtualenvwrapper.sh,在使用virtualenvwrapper时, 需要将virtualenvwrapper.sh的信息读入当前的shell环境。
5、配置lucy用户的.bashrc文件。
[lucy@min ~]$ vim .bashrc# 在脚本的最后添加如下语句if [ -f /home/lucheng/python352/bin/virtualenvwrapper.sh ]; then export WORKON_HOME=$HOME/.virtualenvs source /home/lucy/python352/bin/virtualenvwrapper.shfi
添加完之后记得重新加载.bashrc配置文件。
[lucy@min ~]$ source .bashrc/usr/bin/python: No module named virtualenvwrappervirtualenvwrapper.sh: There was a problem running the initialization hooks. If Python could not import the module virtualenvwrapper.hook_loader,check that virtualenvwrapper has been installed forVIRTUALENVWRAPPER_PYTHON=/usr/bin/python and that PATH isset properly.
提示没有正确设置VIRTUALENVWRAPPER_PYTHON环境变量的值,需要在.bashrc配置文件中添加VIRTUALENVWRAPPER_PYTHON的值:
if [ -f /home/lucy/python352/bin/virtualenvwrapper.sh ]; then export WORKON_HOME=$HOME/.virtualenvs export VIRTUALENVWRAPPER_PYTHON=$HOME/python352/bin/python3 source /home/lucy/python352/bin/virtualenvwrapper.shfi
再重新加载.bashrc配置文件即可。
6、使用mkvirtualenv创建工作空间。
[lucy@min ~]$ mkvirtualenv --python=/home/lucy/python352/bin/python3 lucy-python3which: no virtualenv in (/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/lucy/.local/bin:/home/lucy/bin)ERROR: virtualenvwrapper could not find virtualenv in your path
提示报错:virtualenvwrapper在$PATH中找不到virtualenv,只需要把刚刚安装的/home/lucy/python352/bin添加到$PATH中即可。
[lucy@min ~]$ vim .bash_profile PATH=$PATH:$HOME/.local/bin:$HOME/bin:$HOME/python352/bin[lucy@min ~]$ source .bash_profile [lucy@min ~]$ echo $PATH/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/home/lucy/.local/bin:/home/lucy/bin:/home/lucy/.local/bin:/home/lucy/bin:/home/lucy/python352/bin[lucy@min ~]$ mkvirtualenv --python=/home/lucy/python352/bin/python3 lucy-python3Running virtualenv with interpreter /home/lucy/python352/bin/python3Using base prefix '/home/lucy/python352'New python executable in /home/lucy/.virtualenvs/lucy-python3/bin/python3Also creating executable in /home/lucy/.virtualenvs/lucy-python3/bin/pythonInstalling setuptools, pip, wheel...done.virtualenvwrapper.user_scripts creating /home/lucy/.virtualenvs/lucy-python3/bin/predeactivatevirtualenvwrapper.user_scripts creating /home/lucy/.virtualenvs/lucy-python3/bin/postdeactivatevirtualenvwrapper.user_scripts creating /home/lucy/.virtualenvs/lucy-python3/bin/preactivatevirtualenvwrapper.user_scripts creating /home/lucy/.virtualenvs/lucy-python3/bin/postactivatevirtualenvwrapper.user_scripts creating /home/lucy/.virtualenvs/lucy-python3/bin/get_env_details(lucy-python3) [lucy@min ~]$ pythonPython 3.5.2 (default, Aug 16 2016, 22:07:02) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linuxType "help", "copyright", "credits" or "license" for more information.>>>
可以看到,mkvirtualenvwrapper创建完工作空间后会直接跳到工作空间中,若是想退出工作空间,可使用deactivate命令。
(lucy-python3) [lucy@min ~]$ deactivate[lucy@min ~]$
当需要编程时,便又需进入工作空间,可使用workon命令进入某个工作空间。
[lucy@min ~]$ workon lucy-python3(lucy-python3) [lucy@min ~]$
进入工作空间后,便可以随便安装包,在工作空间中安装的包并不会对系统有任何影响,换句话说,安装的包只在工作空间内可用,若是退出了工作空间,便无法使用了。
有时想要查看到底安装了哪些包,可以使用pip list命令进行查看。
(lucy-python3) [lucy@min ~]$ pip listpip (8.1.2)setuptools (25.2.0)wheel (0.29.0)
- CentOS下搭建个人Python开发环境
- centos下python环境搭建
- CentOS搭建python开发环境
- centos搭建python开发环境
- CentOS搭建python开发环境
- CentOS搭建python开发环境
- Centos搭建python开发环境
- CentOS搭建python开发环境
- 在Centos上搭建python开发环境
- 在CentOS下搭建Android 开发环境
- centos下快速搭建LNMP开发环境
- centos下c++开发环境搭建
- CentOS 7下搭建java开发环境
- CentOS下Pomelo开发环境搭建
- linux centos 下搭建开发环境
- CentOS下搭建爬虫程序开发环境
- Linux centos下VIM开发环境搭建
- CentOS下搭建Java Web开发环境
- java中String.split()
- [hdu 5833 Zhu and 772002] 高斯消元求异或方程组
- 在项目什么时候选择使用GCD,什么时候选择NSOperation?
- Hdu 3666 THE MATRIX PROBLEM(差分约束)
- 51 nod 1183 编辑距离
- CentOS下搭建个人Python开发环境
- css3 扇形
- 用Editplus开发Java
- UVALive 6859--凸包
- ACdream 1083人民城管爱人民
- 高并发的核心技术-幂等的实现方案
- 修改了jsp内容,但是运行在tomcat中没有变化
- android数据传递(三)之Activity传递到Fragment
- awk笔记