Installation using setuptools and pip

Installation using setuptools and pip

NOTE: If you don‘t want to touch system files or you don‘t have root, please see this question on stackoverflow. For everyone else please read on...

Install setuptools and pip

According to the distribute website setuptools and easy_install are old and busted (the version included in Ubuntu 12.04 doesn‘t work with python3), and distribute and pip are the new hotness. So we will use those:

EDIT: Since September 2014, distribute has been merged back into setuptools. So we can use setuptools and easy_install again to install pip. Use:

wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python

or

wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python3

if you‘re using python 3, then install pip with

sudo easy_install pip

Optional: Turn on bash autocomplete for pip
Run

pip completion --bash >> ~/.bashrc

and run source ~/.bashrc to enable

Use pip to install virtualenv and virtualenvwrapper

The reason we are also installing virtualenvwrapper is because it offers nice and simple commands to manage your virtual environments.

sudo pip install virtualenv
sudo pip install virtualenvwrapper

Setup virtualenv

First we export the WORKON_HOME variable which contains the directory in which our virtual environments are to be stored. Let‘s make this ~/.virtualenvs

export WORKON_HOME=~/.virtualenvs

now also create this directory

mkdir $WORKON_HOME

and put this export in our ~/.bashrc file so this variable gets automatically defined

echo "export WORKON_HOME=$WORKON_HOME" >> ~/.bashrc

Setup virtualenvwrapper

To use virtualenvwrapper we need to import its functions in our ~/.bashrc

echo "source /usr/local/bin/virtualenvwrapper.sh" >> ~/.bashrc

We can also add some extra tricks like the following, which makes sure that if pip creates an extra virtual environment, it is also placed in our WORKON_HOME directory:

echo "export PIP_VIRTUALENV_BASE=$WORKON_HOME" >> ~/.bashrc

Source ~/.bashrc to load the changes

source ~/.bashrc

Test if it works

Now we create our first virtual environment

mkvirtualenv test

You will see that the environment will be set up, and your prompt now includes the name of your active environment in parentheses. Also if you now run

python -c "import sys; print sys.path"

you should see a lot of /home/user/.virtualenv/... because it now doesn‘t use your system site-packages.

You can deactivate your environment by running

deactivate

and if you want to work on it again, simply type

workon test

Finally, if you want to delete your environment, type

rmvirtualenv test

Enjoy!



Important note:

  • All virtual environments have pip automatically installed, never call pip with sudo in your virtual environment, because this will use the system wide pip.


Thanks to the author of this blogpost.

时间: 2024-10-20 16:34:07

Installation using setuptools and pip的相关文章

setuptools以及pip安装简单说明

先来简单说一下这两个有什么作用吧!安装这两者是方便我们下载与python相关的工具套件,库等,而不用我们一个个找到并下载.比如你安装了setuptools之后,配置好环境变量后,便可以简单的使用easy_install pip来完成对pip的安装. 关于setuptools的安装 我们先要检查我们的Python环境有没有配置好,假如没有的话,你还是看一下如何安装Python并且配置环境变量.假如成功配置之后,打开命令提示符(快捷键是windows键+r),然后在上面输入python之后,会显示如

安装setuptools和pip 以及安装时报错解决

1.安装setuptools和pip 安装完python后,需要安装pip,参考网上教程有说可以用easy_install安装pip,那就先安装easy_install再安装pip,安装easy_install和pip的方法如下: wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz tar -vxf setuptools-1.4.2.tar

转载 Python 安装setuptools和pip工具操作方法(必看)

本文章转载自 脚本之家 http://www.jb51.net  感谢! setuptools模块和pip模块是python进行第三方库扩展的极重要工具,例如我们在需要安装一些爬虫或者数据分析的包时就可以使用pip install命令来直接安装这些包了,因此pip工具一定要提前安装. 一.安装setuptools 在python交互界面执行如下命令,脚本我单独拿出来: ? 1 2 3 4 from urllib import urlopen data = urlopen('http://peak

python3.6升级及setuptools、pip安装

升级python3.6 1.打开官网www.python.org,找到最新3.6.3版本,复制下载链接 2.创建/app目录,wget下载到该目录下,编译安装 mkdir /app cd /app wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz tar xf Python-3.6.3.tgz cd Python-3.6.3 #安装编译依赖包 yum install gcc glibc zlib-devel openssl

centos源码方式安装ipython2.7,setuptools、pip并解决ipython不能不能使用方向键的问题

安装python 2.7版本 wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tgztar zxvf Python-2.7.8.tgzcd Python-2.7.8./configure --prefix=/usr/local/python2.7  --with-readlinemake (解决方向键问题) --with-openssl --with-openssl-devel (安装pip需要)  --with zlib(安装

Centos6.5 python2.6.6升级2.7.13,安装setuptools和pip

1.安装Development Tools和相关编译安装的组件 # yum -y groupinstall "Development tools" # yum -y install openssl-devel zlib-devel ncurses-devel bzip2-devel readline-devel libtool-ltdl-devel sqlite-devel tk-devel tcl-devel 2.从搜狐镜像站下载并解压最新Python 2.7.13的源代码 # wg

win7下python2.6如何安装setuptools和pip

1. 下载 setuptools-0.6c9.tar.gz 下载地址:http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c9.tar.gz 将压缩包的ez_setup解压出来,在cmd中运行 python ez_setup virtualenv 之后会在python的安装目录创建Scripts目录,目录中有几个文件 将Scripts添加入环境变量: 在cmd中执行 python -m easy_install pi

CentOS6.5安装setuptools、pip和django

安装pip需要先安装setuptools: # unzip setuptools-18.3.2.zip # cd setuptools-18.3.2 # python setup.py install 安装pip: # tar -zxvf pip-7.1.2.tar.gz # cd pip-7.1.2 # python setup.py install 安装Django: # pip install django 如果在安装Django的时候提示:ImportError: cannot impo

python3、ipython3、setup-tools、pip等环境搭建详细总结

第一个python脚本: [[email protected] ~]# cat helloworld.py print("hello world") [[email protected] ~]# python helloworld.py hello world 安装python3及ipython整体环境,非常麻烦,不注意会经常报错,安装不成功,折腾了一天才搞定,流程记录如下: 第一步:安装python3.5 1.CentOS6.5 安装Python 的依赖包 yum groupinst