gpt4 book ai didi

python - Ubuntu Oneiric 11.10 中两个 Python 版本冲突问题 : ImportError: No module

转载 作者:行者123 更新时间:2023-12-01 05:40:20 25 4
gpt4 key购买 nike

我使用 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 呢?!

最佳答案

安装 python 时使用以下步骤
使用前缀指定安装目录

 ./configure --prefix=/scratch/bin/
make
sudo make install

然后每次你运行一个新的终端时你都指定

export PATH="$PATH:/scratch/bin/"

告诉Python的安装目录在哪里

这样你就可以使用任意数量的Python

关于python - Ubuntu Oneiric 11.10 中两个 Python 版本冲突问题 : ImportError: No module,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17705736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com