1

I am a Project Manager in a new position, I need to install Django on my local machine to try and see how the workings of the language are constructed and maybe make a small web app to get familiar with it.

Problem is the current machine already had Python 2 on it so when I installed Python3 I now have 2 versions of python. I have created a new Django project but when I run:

sudo python manage.py runserver

I go to localhost and all I get is errors refering to Django 1.5 and Python 2. I am guessing its got to do with a versioning problem. So what I did was run:

sudo python3 manage.py runserver

and I get the following returned to me alot of info on command terminal starting with:

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

and ending with:

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

Thing is it looks like all went well and I don't receive any Error messages, however, no server was actually started.

What can I do to get this up and running. Seems to be taking way to much time for me to get this set up. Any help would be greatly appreciated.

Dom
  • 1,018
  • 2
  • 11
  • 20
  • You should be using a [virtual environment](http://docs.python-guide.org/en/latest/dev/virtualenvs/) to keep everything separate. – Two-Bit Alchemist Feb 25 '15 at 16:54
  • yea I have a virtual environment set up for the Django project I made and I installed Django 1.7 on there, but should I also be installing versions of python on there as well?, as well as running the server from there? – Dom Feb 25 '15 at 16:56
  • Yes, that's rather the point. The virtualenv has its own version of Python and once you "activate" it, you run everything under it to keep it separate from your local filesystem. – Two-Bit Alchemist Feb 25 '15 at 16:58
  • I see, however I didnt install python on the virtual environment I created. all I did was pip install Django and the localhost error message is showing Users/username/mysite2', '/Users/username/venv1/lib/python2.7/site-packages/setuptools-12.2-py2.7.egg', .. so would I jsut install Python 3 in that virtual machine, also then how would I deal with Django calling the correct version of python? – Dom Feb 25 '15 at 17:05

2 Answers2

4

for python3.4:

EDIT: install python3-dev too:

sudo apt-get install python3-dev

To make a virtualenv with default python version python3.4:

mkvirtualenv virtualenv_name -ppython3.4  

replace virtualenv_name with the name you want to give to your environment

Then install pip for python3:

sudo apt-get install python3-pip

and then to install django after you activate your virtualenv:

pip3 install django

for python2.7:

mkvirtualenv virtualenv_name -ppython2.7

replace virtualenv_name with the name you want to give to your environment

Then install pip normaly:

sudo apt-get install python-pip

and once you activate your virtualenv:

pip install django
Tony
  • 2,382
  • 7
  • 32
  • 51
  • Im working on OSX, cannot get python3-dev using brew, is there any other method? Also, when I try to use the command mkvirtualenv env_name --python3.4 I get the error "Python: error: no such option: -p" – Dom Feb 25 '15 at 21:36
  • try this and tell me if it works: mkvirtualenv --python=python3_path myenv – Tony Feb 25 '15 at 21:39
  • I put in 'mkvirtualenv --python=/usr/local/bin/python3 firstpython' get - Python: error: no such option: --python – Dom Feb 25 '15 at 21:44
0

If you need concurrent versions the cleanest way to do it is to install virtualenv/virtualenvwrapper (package source)

and have a dedicated local environment for the project.

Here are some instructions on how to set up that environment that will let you work on them in isolation. http://railslide.io/virtualenvwrapper-python3.html

HTH

Kelvin
  • 1,357
  • 2
  • 11
  • 22
  • I tried to do this. I am on OSX and when running the server I still get Django errors listing Python 2 as the directories – Dom Feb 25 '15 at 18:38
  • 2 notes: 1) don't use sudo when installing inside a virtualenv. 2) this link should be helpful: http://stackoverflow.com/questions/1534210/use-different-python-version-with-virtualenv – Kelvin Feb 25 '15 at 19:14
  • Same thing as other comments, when I run the virtualenv -p /usr/bin/python2.6 command, I get the following error "Python: error: no such option: -p" – Dom Feb 25 '15 at 21:38
  • what happens when you just type virtualenv --help ? also "which virtualenv"? – Kelvin Feb 25 '15 at 21:49
  • its wierd I see it listed there: --version show program's version number and exit -h, --help show this help message and exit -v, --verbose Increase verbosity. -q, --quiet Decrease verbosity. -p PYTHON_EXE, --python=PYTHON_EXE The Python interpreter to use, e.g., --python=python2.5 will use the python2.5 interpreter to create the new environment. The default is the interpreter that virtualenv was installed with (/usr/bin/python) – Dom Feb 25 '15 at 21:52