一个 python 的交互式 shell,比默认的python shell 好用得多,支持变量自动补全,自动缩进,支持 bash shell 命令,内置了许多很有用的功能和函数。
若用的是fish shell,建议使用virtualfish替代 virtualenvwrapper: https://github.com/adambrenecki/virtualfish,注意,如果使用 vf new -p /usr/bin/python3.5 env35 创建出错,可以使用 sudo pip install setuptools --no-use-wheel --upgrade 解决问题; 如果你想这virtualfish的virtualenv 下使用 ipython, 建议直接这虚拟环境下执行:pip install ipython (这样该虚拟环境下就可以直接运行 ipython), 尽量不要在shell环境下用 sudo 执行: sudo apt-get install ipython (这样的后果可能导致虚拟环境下ipython执行不成功)。
Python的dist-packages目录和site-packages目录的区别:
0、site-packages里面放的是第三方包。
1、sudo apt-get install 安装的package存放在 /usr/lib/python2.7/dist-packages目录中。
2、pip 或者 easy_install安装的package存放在/usr/local/lib/python2.7/dist-packages目录中。
3、手动从源代码安装的package存放在site-packages目录中。
Ubuntu下安装pip的方法:
$ sudo apt-get install python-pip python-dev build-essential
$ sudo pip install --upgrade pip
$ sudo pip install --upgrade virtualenv
virtualenv 和 virtualenvwrapper:virtualenv、fabric 和 pip 是 pythoneer 的三大神器
virtualfish的安装很简单:
pip install virtualfish
- Edit
~/.config/fish/config.fish
, adding a line that readseval (python -m virtualfish)
注意 eval (python -m virtualfish) 必须添加到文件的最后,因为它依赖PATH,若你自己设定过 PATH,就必须添加在你自己设定的语句后面
virtualfish的使用:
-
vf new [<options>] <envname>
- Create a virtualenv. Note that<envname>
must be last. -
vf ls
- List the available virtualenvs. -
vf activate <envname>
- Activate a virtualenv. (Note: Doesn't use theactivate.fish
script provided by virtualenv.) -
vf deactivate
- Deactivate the current virtualenv. -
vf rm <envname>
- Delete a virtualenv. -
vf tmp [<options>]
- Create a temporary virtualenv with a randomly generated name that will be removed when it is deactivated. -
vf cd
- Change directory to currently-activated virtualenv. -
vf cdpackages
- Change directory to the currently-activated virtualenv's site-packages. -
vf addpath
- Add a directory to this virtualenv'ssys.path
. -
vf all <command>
- Run a command in all virtualenvs sequentially. -
vf connect
- Connect the current working directory with the currently active virtualenv. This requires the :ref:`auto-activation plugin <auto_activation>` to be enabled in order to have any effect besides creating a :file:`.venv` file in the current directory.
Using Different Pythons
By default, the environments you create with virtualenv
(and, by extension, virtualfish) use the same Python version that virtualenv
was installed under, which will usually be whatever your default system Python is.
If you want to use something different in a particular virtualenv, just pass in the --python PYTHON_EXE
(-p
for brevity) argument to vf new
, where PYTHON_EXE
is any Python executable, for example:
vf new -p python3 my_python3_env
vf new -p /usr/bin/pypy my_pypy_env