我使用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运行virtualenv而不是2.7.2+?!
答案 0 :(得分:2)
安装python时,请使用以下步骤
使用前缀指定安装目录
./configure --prefix=/scratch/bin/
make
sudo make install
然后每次你运行一个新的终端你都指定了
export PATH="$PATH:/scratch/bin/"
告诉Python的安装目录在哪里
这样你可以使用任意数量的蟒蛇
答案 1 :(得分:0)
您是使用apt-get安装的还是从源代码构建的?
如果从源代码构建,您确定安装已成功完成吗?通常,为了从源代码构建Python,必须执行以下步骤
./configure
make
sudo make install
(可能不需要sudo
,但make脚本会尝试更改/usr/
目录中的文件。在你的python源目录中。最后一个命令将python复制到/usr/
目录。如果您想将其安装在其他地方,则必须将--path=XXX
(如果我没记错的话)传递给./configure
。
答案 2 :(得分:0)
pip
是一个Python程序。从命令行运行pip
时,它使用特定的Python可执行文件来运行该程序。 pip
将在 Python可执行文件可以找到它们的位置安装模块。
运行sudo pip install some_package
时,操作系统会查看shebang line以确定要运行的Python可执行文件。
键入which pip
并查看文件中的第一行,以查看链接到哪个python可执行文件。
要为新的python2.7.5安装软件包,您可以install a new pip
.或者,您可以运行/usr/local/bin/python pip ...
,但我认为管理多个python安装的最简单方法是使用{{3 }}
如果您使用virtualenv(我强烈推荐),则会自动安装新的pip
,因为它是其依赖项之一。
如果你走这条路,我建议你也安装virtualenv。
如果您全局安装pip,virtualenvwrapper
python get-pip.py
或
python setup.py install
你在这一行使用的python可执行文件设置了那个版本的pip和那个版本的python之间的“链接”。
如何使用checkinstall删除自定义Python:
sudo apt-get install libsqlite3-dev libgdbm-dev liblzma-dev checkinstall
sudo apt-get build-dep python
http://www.python.org/ftp/python/2.7.5/Python-2.7.5.tar.bz2
tar xvjf Python-2.7.5.tar.bz2
cd Python-2.7.5
# inspect the options
./configure --help
./configure
make
make test
sudo checkinstall -D --fstrans=no make install
# Accept the default answers EXCEPT that you MUST change the name to something
# other than python. That way, the name of your custom package does not conflict
# with the name of Ubuntu's "python" package
Should I create a default set of package docs? [y]:
Enter a number to change any of them or press ENTER to continue: 2
Enter new name:
>> python275
Copying files to the temporary directory...OK
# wait, wait, wait...
# python2.7.5 is now installed in /usr/local/bin
# remove it with:
sudo dpkg -r python275