0

In centOS 6.7 python2.6 is pre installed. I wanted to install python2.7 because django doesn't support python2.6.

While doing migration i am getting this issue.

What i guess in the issue is its taking python2.6. I just need to add the PythonPath in manage.py so that i can use python2.7 independently.

Note: i dont need to uninstall python2.6 because some services are using python2.6.

Any help will be apprecitaed

File "/usr/bin/django-admin", line 7, in <module>
    from django.core.management import execute_from_command_line
  File "/usr/lib/python2.6/site-packages/django/core/management/__init__.py", line 68
    commands = {name: 'django.core' for name in find_commands(__path__[0])}

Thanks in advance

parker
  • 87
  • 1
  • 8
  • Adding the python path to manage.py won't help any since you're already running it with 2.6, you just need to run manage.py with the correct python version `path/to/python2.7 manage.py`... (although a virtualenv would be better) – Sayse Dec 02 '15 at 10:12
  • This happens when you run: `python2.7 manage.py ...` or you're still using `python manage.py ...`? – Maciek Dec 02 '15 at 10:12

2 Answers2

1

One way of doing it (and recommended one) is to create separate virtualenv for you django project and activate it every time you're trying to use manage.py.

Second one is to replace system python with newer one. It's risky, but should work fine for that version of Cent OS.

GwynBleidD
  • 20,081
  • 5
  • 46
  • 77
  • Yup, virtualenv is the way to go. Depending on your project and the command you want to run, it might be necessary to set the DJANGO_SETTINGS_MODULE to the appropriate settings file – user2390182 Dec 02 '15 at 10:18
1

You can have multiple python running on your system. No need to update the existing python version of your OS as it might corrupt some applications. First install python2.7 on your system. Follow below steps (I didnt tested it, you can find enough links to install it on your system. You can use this)

cd /opt
wget --no-check-certificate  
https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure --prefix=/usr/local
make && make altinstall

Once done type python2.7 on your terminal and you'll see python2.7 console.

Now to run your django project on python 2.7 create a virtualenv with python 2.7 using below command

virtualenv -p /usr/bin/python2.7 <path/to/new/virtualenv/>

Refer this for virtualenv setup.

Now activate the virtualenv and type python and you will notice the session is now using python2.7. Now you can setup your django project using that virtual environment.

Community
  • 1
  • 1
Tarun Behal
  • 908
  • 6
  • 11
  • Thats Ok. Could u please tell how django knows which version of python to use? Some where it must be written that set PYTHONPATH – parker Dec 02 '15 at 10:42
  • Once you create a virtualenv and activate it, then django will use that python version. Virtualenv takes cares of pythonpath so you dont need to make any such change. – Tarun Behal Dec 02 '15 at 10:45
  • I still have a doubt. May be i am wrong but i just need to know how django set virtualenv because if i want to set two python version then what and all i need to do? – parker Dec 02 '15 at 10:51
  • First of all, you need to get more clarification on virtualenv. VirtualEnv creates a environment where your application will run. So django will use whichever python your environment has. So if there is no virtualenv django uses python2.6 (your system python). Thats why its recommended to use virtualenv so all your packages and python remains isolated and doesnt impacts the system. – Tarun Behal Dec 02 '15 at 11:40
  • Thats why you've to install python 2.7 on your own and create a new environment which will be used by your django app. There are tons on articles on net about virtualenv and setting django project in it. Let me know if you need any further help on the same. Happy to help you. :) – Tarun Behal Dec 02 '15 at 11:42