简体   繁体   English

将默认 python 版本从 2.6.6 更改为 2.7 并配置 django

[英]Change default python version from 2.6.6 to 2.7 and also configure django

I am new to linux (Ubuntu) and python (Django).我是 linux (Ubuntu) 和 python (Django) 的新手。 By default there is python 2.6.6 in my linux, I installed python 2.7.默认情况下,我的 linux 中有 python 2.6.6,我安装了 python 2.7。 In the command prompt when I type python it goes to python 2.6.6, I want to change my default python to 2.7.在命令提示符中,当我键入 python 时,它转到 python 2.6.6,我想将我的默认 python 更改为 2.7。

Ubuntu might have a Python2.7 package. Ubuntu 可能有 Python2.7 package。 If so, install that then use that to create a virtualenv and put Django inside that.如果是这样,请安装它,然后使用它创建一个virtualenv并将 Django 放入其中。

I recommend to use pythonbrew which can install and switch between multi Python interpreters in your $HOME without touch your system directories.我建议使用pythonbrew ,它可以在 $HOME 中安装和切换多个 Python 解释器,而无需触及系统目录。

BTW, when install python, use the command顺便说一句,安装 python 时,使用命令

pythonbrew install --no-test 2.7.2

to skip unitest could speed up the installation a lot.跳过 unitest 可以大大加快安装速度。

The easiest way would be to modify your path and make sure the path to Python 2.7 is before Python 2.6.最简单的方法是修改路径并确保 Python 2.7 的路径在 Python 2.6 之前。 This is what I have done on my Mac to achieve similar things.这就是我在我的 Mac 上为实现类似的事情所做的。

EDIT编辑
I agree with Noufal Ibrahim in the fact about using virtualenv .我同意 Noufal Ibrahim 关于使用virtualenv的事实。 I would also suggest looking into virutalenv wrapper .我还建议研究virutalenv wrapper However, you still might have trouble using Python 2.7 is your path is not configured correctly, using an Ubuntu package for the install should take care of the path for you.但是,您在使用 Python 2.7 时仍然可能会遇到问题,因为您的路径配置不正确,请使用Ubuntu package 安装路径。 Otherwise to install virtualenv from the bash shell, you can do something along the lines.否则,要从 bash shell 安装 virtualenv,您可以这样做。

$ path/to/python27/python easy_install virutalenv
$ pip install virtualenvwrapper

I believe when installing virtualenv, it will set your PATH for you.我相信在安装 virtualenv 时,它会为您设置 PATH。 You can confirm this by doing:您可以通过执行以下操作来确认:

$which python

This should now show Python 2.7.现在应该显示 Python 2.7。

It's all about the links, I tell ya.我告诉你,这都是关于链接的。 Look at the links.看看链接。 Check the inode's link count for python2.5, python2.6, python2.7, python3.2, etc. Notice those are greater than one.检查 inode 的 python2.5、python2.6、python2.7、python3.2 等的链接计数。注意这些大于 1。

Just hunt down the duped link to "python", fix by unlink, and relink it.只需寻找到“python”的欺骗链接,通过取消链接修复,然后重新链接它。 It may be a real link, or just a sym link.它可能是一个真实的链接,或者只是一个符号链接。 unlink with extreme prejudice.与极端偏见脱节。

-rwxr-xr-x  2 root  admin  12392 Oct  4  2009 /opt/local/bin/python2.5*
-rwxr-xr-x  2 root  wheel  12392 Jul 23 17:14 /opt/local/bin/python2.6*
lrwxr-xr-x  1 root  wheel  72 Nov  7  2008 /usr/bin/python@ -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python
-rwxrwxr-x  1 root  admin  41476 Jul  3  2010 /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7*
-rwxr-xr-x  3 root  wheel  2072216 Jul 27 19:34 /usr/local/bin/python3.2*

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在OSX Snow Leopard上安装IPython以使用非默认的python版本(即python2.6.6 / python2.7) - Installing IPython to work with a non-default python version (i.e python2.6.6/python2.7) on OSX Snow Leopard Python如何将默认版本从python 3.5更改回python 2.7 - Python How to change default version back from python 3.5 to python 2.7 如何在Anaconda中将默认Python版本从3.5更改为2.7 - How do I change default Python version from 3.5 to 2.7 in Anaconda 我在virtual-env中的python是2.7,但是Django调试屏幕显示了系统的2.6.6 - My python in virtual-env is 2.7 but the Django debug screen shows the system's 2.6.6 从版本python2.6.6的位置导入pandas - Importing pandas from a location for version python2.6.6 在 AWS Elastic Beanstalk 中将 Python 版本从 3.6 更改为 2.7 - Change Python Version from 3.6 to 2.7 in AWS Elastic Beanstalk 无法从 2.7-3.6 更改 python 的版本 - Not being able to change version of python from 2.7-3.6 将 django 从 python2.6 更改为 python2.7 - change django from python2.6 to python2.7 将Kivy的默认Python解释器从2.7更改为3.3 - Change default Python interpreter for Kivy from 2.7 to 3.3 Python-在python 2.6.6版本中安装Argpath的问题 - Python - Issue in Installing Argpath for python 2.6.6 version
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM