Installation using setuptools and pip
2015-10-28 09:37
453 查看
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 websitesetuptoolsand
easy_installare old and busted (the version included in Ubuntu 12.04 doesn't work with python3), and
distributeand
pipare the new hotness. So we will use those:
EDIT: Since September 2014,
distributehas been merged back into
setuptools. So we can use
setuptoolsand
easy_installagain 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
pipwith
sudo easy_install pip
Optional: Turn on bash autocomplete for pip
Run
pip completion --bash >> ~/.bashrc
and run
source ~/.bashrcto 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 theWORKON_HOMEvariable 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
~/.bashrcfile so this variable gets automatically defined
echo "export WORKON_HOME=$WORKON_HOME" >> ~/.bashrc
Setup virtualenvwrapper
To usevirtualenvwrapperwe 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
pipcreates an extra virtual environment, it is also placed in our
WORKON_HOMEdirectory:
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
pipwith sudo in your virtual environment, because this will use the system wide
pip.
Thanks to the author of this blogpost.
相关文章推荐
- 找找3
- 校验码(奇偶校验 、海明校验、循环冗余校验码CRC)
- https原理及tomcat配置https方法
- Windows-设置系统服务不开机启动
- HDU1754 I Hate It
- Linux的tee命令
- Spring随笔2
- linux input子系统(二)- input event drivers evdev 驱动分析
- Leetcode -- Expression Add Operators
- Xcode技巧 - 3
- android项目导包问题的解决方案
- android基础之页面间跳转传值,用Bundle+Intent
- js获取web项目根目录
- 读取文本
- jqueryeasy ui 的 accordion 和 tabs控件
- eclipse中一些常见svn图标的含义,超全的
- Hive学习
- 互联网是一巨大的FPGA
- POJ 2139
- intellij Idea快捷键