In ubuntu 16.04 I have in bashrc:
alias python=python3.6
In other words, the command python starts python 3.6.
Now I want a virtualenv with python 2.7.
I have installed virtualenv:
virtualenv -p python2 pgadmin4
Then activated it.
Now check:
$ which python
/home/michael/PycharmProjects/venv/pgadmin4/bin/python
Doublecheck:
(pgadmin4) michael@michael-desktop:~/PycharmProjects/venv/pgadmin4/bin$ ls -la
total 3516
drwxrwxr-x 2 michael michael 4096 окт 12 13:05 .
drwxrwxr-x 7 michael michael 4096 окт 12 13:05 ..
-rw-rw-r-- 1 michael michael 2102 окт 12 13:05 activate
-rw-rw-r-- 1 michael michael 1044 окт 12 13:05 activate.csh
-rw-rw-r-- 1 michael michael 2242 окт 12 13:05 activate.fish
-rw-rw-r-- 1 michael michael 1137 окт 12 13:05 activate_this.py
-rwxrwxr-x 1 michael michael 272 окт 12 13:05 easy_install
-rwxrwxr-x 1 michael michael 272 окт 12 13:05 easy_install-2.7
-rwxrwxr-x 1 michael michael 244 окт 12 13:05 pip
-rwxrwxr-x 1 michael michael 244 окт 12 13:05 pip2
-rwxrwxr-x 1 michael michael 244 окт 12 13:05 pip2.7
lrwxrwxrwx 1 michael michael 7 окт 12 13:05 python -> python2
-rwxrwxr-x 1 michael michael 3546104 окт 12 13:05 python2
lrwxrwxrwx 1 michael michael 7 окт 12 13:05 python2.7 -> python2
-rwxrwxr-x 1 michael michael 2361 окт 12 13:05 python-config
-rwxrwxr-x 1 michael michael 251 окт 12 13:05 wheel
Well, just writing python must run python2.
But:
$ python
Python 3.6.2 (default, Jul 20 2017, 08:43:29)
Could you give me a kick here?
答案 0 :(得分:1)
当您激活virtualenv时,会重写PATH环境变量,以便为您的virtualenv的bin
目录提供更多优先级。
which python
命令会告诉您所期望的路径,因为忽略最终配置的alias
。它查看PATH环境变量并尝试解析当前的python路径。
alias
,当您键入python
时,bash会将命令解析为不在您的virtualenv bin目录中的python3.6
并转到系统一。
唯一可行的解决方案是:
python3.6 -> python
文件夹中添加符号链接bin