我使用 make install 而不是 altinstall 安装了 python 2.7.5
以前是 2.7.2+
现在当我运行 python 它给出
ImportError: cannot import name MAXREPEAT
我知道这里已经有与此相关的条目。但是我以前也没有安装 virtualenv。
如果我运行python2.7
它运行完美。现在,当我尝试导入像 mysqldb 这样的库时,它说该模块不存在。我在安装python2.7之前安装了它。
解决办法是什么?我应该卸载整个 python 还是应该如何只卸载 python2.7.5 还是应该保留它?如果我保留它,那么我该如何导入这些模块?
**最新更新**
me@me:/usr/local/bin$ dir python2*
python2 python2-config python2.7 python2.7-config
和:
/usr/local/bin$ ls -l
total 1776
-rwxrwxr-x 1 root root 101 Jul 17 20:17 2to3
-r-xr-xr-x 1 root root 7223 Mar 31 20:47 config_data
-rwxr-xr-x 1 root root 299 Jul 18 20:53 easy_install
-rwxr-xr-x 1 root root 307 Jul 18 20:53 easy_install-2.7
-rwxrwxr-x 1 root root 99 Jul 17 20:17 idle
-r-xr-xr-x 1 root root 3910 Mar 31 20:47 json_pp
-r-xr-xr-x 1 root root 487 Mar 31 20:47 package-stash-conflicts
-rwxr-xr-x 1 root root 281 Jul 17 19:51 pip
-rwxr-xr-x 1 root root 289 Jul 17 19:51 pip-2.7
-rwxrwxr-x 1 root root 84 Jul 17 20:17 pydoc
lrwxrwxrwx 1 root root 7 Jul 18 23:04 python -> python2
lrwxrwxrwx 1 root root 14 Jul 18 23:04 python-config -> python2-config
lrwxrwxrwx 1 root root 9 Jul 18 23:04 python2 -> python2.7
lrwxrwxrwx 1 root root 16 Jul 18 23:04 python2-config -> python2.7-config
-rwxr-xr-x 1 root root 1737376 Jul 18 23:03 python2.7
-rwxr-xr-x 1 root root 1674 Jul 18 23:04 python2.7-config
-rwxrwxr-x 1 root root 18547 Jul 17 20:17 smtpd.py
-rwxr-xr-x 1 root root 316 Jul 18 21:10 virtualenv
-rwxr-xr-x 1 root root 324 Jul 18 21:10 virtualenv-2.7
重新安装它会解决在 ubuntu 中获取和运行默认 2.7.2+ 的问题吗?:https ://launchpad.net/ubuntu/oneiric/+source/python-defaults/2.7.2-7ubuntu2
*事先更新*
现在我可以从 bash 运行 python
这是新的问题。它适用于我使用 pip 安装的每个模块。
可以导入来自 lib 的现有模块,但不能导入新安装的模块:
me:~$ sudo pip install requests
Downloading/unpacking requests
Downloading requests-1.2.3.tar.gz (348kB): 348kB downloaded
Running setup.py egg_info for package requests
Installing collected packages: requests
Running setup.py install for requests
Successfully installed requests
Cleaning up...
me:~$ python -i
Python 2.7.5 (default, Jul 17 2013, 20:16:12)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
>>>
检查 python 的版本后,它在本地运行,冲突问题:
me:~$ python
Python 2.7.5 (default, Jul 17 2013, 20:16:12)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
me:~$ sudo python
[sudo] password for me:
Python 2.7.5 (default, Jul 17 2013, 20:16:12)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
me:~$ which python
/usr/local/bin/python
me:~$ sudo which python
/usr/local/bin/python
me:~$ sudo which python2.7
/usr/local/bin/python2.7
me:~$ which python2.7
/usr/local/bin/python2.7
我认为它的运行方式相同。接着..
me:/usr/local/bin$ dir python2.7
python2.7
me:/usr/local/bin$ cd /usr/bin
me:/usr/bin$ dir python2.7
python2.7
me:/bin$ cd /usr/bin
me:/usr/bin$ dir python
python
me:/usr/local/bin$ dir python
python
me:/usr/local/bin$ dir python2.7
python2.7
还要检查以下内容:
~$ which pip
/usr/local/bin/pip
好的,现在我安装了 virtualenv,这就是我所做的
(foldername)me@me:~/caller$ sudo pip install requests
Requirement already satisfied (use --upgrade to upgrade): requests in /usr/local/lib/python2.7/dist-packages
Cleaning up...
(foldername)me@me:~/caller$ python -i
Python 2.7.2+ (default, Jul 20 2012, 22:15:08)
[GCC 4.6.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
现在我们可以看到 2.7.2+ 又回来了!那么现在发生了什么??怎么了?
不建议从 linux 卸载旧的 python。那么我怎样才能运行带有 2.7.5 而不是 2.7.2+ 的 virtualenv 呢?!