I had to deploy a django project on CentOS 6.5 and here are the steps to set up Python and then Django. The problem with CentOS 6.5 is that it comes with python 2.6.6 and it's package installer yum relies on it.
Although we can install python 2.7.x and soft link 2.7.x as the system default, it will break yum and who knows what else relies on 2.6.6. Thus, I am installing python 2.7.x via pyenv, which is suggested by this blog post.
This solution is cleaner as it does not temper with the OS default python 2.6.6.
- Update all of yum's package
- Install pyenv, which works like rbenv:
Put the following lines into your .bashrc file:
Then, reload bashrc:
This will enable the pyenv command in bash.
- Install these packages before installing python:
- Use this command to list all of the 2.7.x version of python (grep 3.x for python 3):
- Install the python version you prefer:
- Use the newly installed version of python:
You can list all python versions abailable to pyenv by:
- Update pip to its latest version:
Now, we have everything setup and ready to go. The natural thing to do next is to install virtualenv and virtualenvwrapper:
Installing virtualenv and virtualenvwrapper
WARNING: DO NOT install virtualenv and virtualenvwrapper !!!
Let me tell you what happend after I installed both via pip. I put the following lines in .bashrc
Then, I was disconnected from the cloud server with the following warning:
It doesn't matter what I try, I cannot connect to the cloud server anymore because every time I login successfully, I get disconnected from the server with the same error above. I cannot even login using the VNC connection provided by the cloud service provider. The only option I had was to reinstall the image on the cloud server...
I cannot find the cause of this issue on Google, but from the look of it, I messed out the path to bash so everytime I logged in, cannot find bash -> disconnect
Don't worry you can still use virtualenv
If you look under the .pyenv/plugins directory, you can see a directory named pyenv-virtualenv. This is what we can use to create virtual environments.
To create a test environment:
Since we have already set our local version of python to be 2.7.10, this test env inherits from that. But if you did not set the local version, the test env will inherit from the system version of python which may not be what you want. (Note: while running the command above, the 'virtualenv' package is installed to your local version of python)
You can also specify which version of python to use (by putting a version number after 'pyenv virutalenv'):
Once the test environment has been setup, you can verify it by:
You should see something similar to this:
You can switch to the test env by:
To list virtualenvs:
To delete existing virtualenvs:
If you have seen pyenv-virtualenv's github page, you have probably noticed something named pyenv-virtualenvwrapper. Don't install it unless you know what it is. I don't have the time to figure out what it is ATM. But it is definitely NOT the virtualenv + virtualenvwrapper combination you are familiar with. So be cautious!