我是一名新职位的项目经理,我需要在我的本地机器上安装Django,以尝试查看该语言的工作原理,并制作一个小型的Web应用程序以熟悉它。
问题是当前的机器上已经安装了Python 2,所以当我安装Python3时,我现在有2个版本的python。我创建了一个新的Django项目,但是当我运行时:
sudo python manage.py runserver
我转到localhost,我得到的是错误,引用了Django 1.5和Python 2.我猜测它与版本问题有关。所以我做的就是跑:
sudo python3 manage.py runserver
然后我从命令终端返回了很多关于以下内容的信息:
Extracting in /tmp/tmpuaDHV8
Now working in /tmp/tmpuaDHV8/setuptools-12.2
Installing Setuptools
running install
Checking .pth file support in /Library/Python/2.7/site-packages/
/usr/bin/python -E -c pass
TEST PASSED: /Library/Python/2.7/site-packages/ appears to support .pth files
running bdist_egg
running egg_info
writing requirements to setuptools.egg-info/requires.txt
writing setuptools.egg-info/PKG-INFO
writing top-level names to setuptools.egg-info/top_level.txt
writing dependency_links to setuptools.egg-info/dependency_links.txt
writing entry points to setuptools.egg-info/entry_points.txt
以:
结尾copying setuptools.egg-info/requires.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
copying setuptools.egg-info/top_level.txt -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
copying setuptools.egg-info/zip-safe -> build/bdist.macosx-10.10-intel/egg/EGG-INFO
creating dist
creating 'dist/setuptools-12.2-py2.7.egg' and adding 'build/bdist.macosx-10.10-intel/egg' to it
removing 'build/bdist.macosx-10.10-intel/egg' (and everything under it)
Processing setuptools-12.2-py2.7.egg
Removing /Library/Python/2.7/site-packages/setuptools-12.2-py2.7.egg
Copying setuptools-12.2-py2.7.egg to /Library/Python/2.7/site-packages
setuptools 12.2 is already the active version in easy-install.pth
Installing easy_install script to /usr/local/bin
Installing easy_install-2.7 script to /usr/local/bin
Installed /Library/Python/2.7/site-packages/setuptools-12.2-py2.7.egg
Processing dependencies for setuptools==12.2
Finished processing dependencies for setuptools==12.2
看起来一切顺利,我没有收到任何错误消息,但是,实际上没有启动任何服务器。
我该怎么做才能让它正常运行。我似乎已经花了很多时间来完成这个设置。任何帮助将不胜感激。
答案 0 :(得分:4)
for python3.4:
编辑:安装python3-dev:
sudo apt-get install python3-dev
使用默认的python版本python3.4创建virtualenv:
mkvirtualenv virtualenv_name -ppython3.4
将virtualenv_name替换为您要为您的环境提供的名称
然后为python3安装pip:
sudo apt-get install python3-pip
然后在激活virtualenv后安装django:
pip3 install django
for python2.7:
mkvirtualenv virtualenv_name -ppython2.7
将virtualenv_name替换为您要为您的环境提供的名称
然后安装pip normaly:
sudo apt-get install python-pip
一旦激活你的virtualenv:
pip install django
答案 1 :(得分:0)
如果您需要并发版本,最简单的方法是安装virtualenv / virtualenvwrapper(package source)
并为项目提供专用的本地环境。
以下是有关如何设置该环境的一些说明,这些环境可让您单独处理它们。 http://railslide.io/virtualenvwrapper-python3.html
HTH