Trouble Upgrading Python / Django on CentOS - python

As you can see by reading my other thread today here, I'm having some troubles upgrading Python.
At the moment I have Python 2.4 with Django installed on a CentOS machine. However I've recently deployed an application that requires 2.5 which has resulted in me installing that and getting into a whole load of mess. My original assumption was that I could direct Django to a different Python version, however as S.Lott informed me, I had it backwards... you attach Django to Python, not the other way round. Which means I currently have: Python 2.4 with Django and Python 2.5.
I've tried a few things so far to no avail. The first idea being an easy_install which would put Django onto the Python 2.5 (So I'd have 2 versions of python with seperate Djangos). Therefore I went into 2.5's directory and did that, which then allowed me to find out that it had just reinstalls it on 2.4, not 2.5. Therefore first question is How do I direct easy_install to Python 2.5, not 2.4?
Is there no way to just hit 'upgrade' and for a full update to occur? I know this may be asking for much, however it just seems like so much hassle and I'm surprised I can't find anyone else complaining. Any help would be greatly appreciated.

I don't know anything about CentOS, but if you have multiple Python version installed and you wan't to install packages using easy_install, you just need to call it with the corresponding Python interpreter. This should install the packing into the site-package directory of Python 2.5:
# /path/to/python-2.5 easy_install Django

assuming your python2.5 interpreter lives in /usr/bin/python2.5, you can install setuptools for python2.5 as such:
curl -O http://peak.telecommunity.com/dist/ez_setup.py
sudo /usr/bin/python2.5 ez_setup.py
Among other things, this installs an "easy_install-2.5" script in your $PATH (check the output of the above command).
Now you have two easy_install scripts: one for python 2.4 ("easy_install") and one for python 2.5 ("easy_install-2.5").
To install Django for your python2.5, use
sudo easy_install-2.5 django
That's it!

easy_install is a shell script the first line of which tells it where python is installed (I am on OSX so can't say exactly what your directories will be )
So you could copy easy_install and change the first line to point to 2.5. (or do as Heas suggests)
Althernatively when you installed python 2.5 there might be a file easy_install-2.5 with the correct python (again these were installed for me under OSX so might be a special version)

You don't need to 'install' Django at all, it just needs to live on the Pythonpath somewhere. Assuming it's currently in the Python2.4 site-packages directory, you can just move it to the 2.5 one:
sudo mv /usr/lib/python2.4/site-packages/django /usr/lib/python2.5/site-packages/django
or whatever the correct path is for CentOS.
However, as I noted on your other question, this won't necessarily help - S.Lott was unfortunately misleading in his answer. To serve Django via modpython or modwsgi with a new Python version, you'll need to recompile those extensions or download packages versions precompiled with Python 2.5.

Related

Install python 2.6 on Mac

I have to use an API which uses Python 2.6 and am having a very difficult time getting it installed on my mac. I have downloaded it but figuring out what I am supposed to write in my bash_profile is exceedingly difficult. For all versions of Python that I have used so far I write
PATH="/Library/Frameworks/Python.framework/Versions/3.7/bin:${PATH}"
export Path
in my bash profile. But I can't do that for python 2.6 because it does not have a bin folder. Does anyone know what I'm suppoed to write on my bash profile in order to get Python to use version 2.6?
I'm aware that one solution is pyenv but I tried that a long time ago and there were too many modules that I could not install with it so I don't like that program.
I'm also hoping brew will work but according to this page
https://formulae.brew.sh/formula/
python 2.6 is no longer available for brew install. And when I run brew install python#2.6 no formulae are found.
My current strategy is to try macports so we'll see how that goes.

What to do after upgrading from Python 2 to Python 3?

Recently I've installed Python 3 after using 2 for quite a while, so I have many libraries for Python that I've installed using pip. I've already started using the symlink python3, but what else do I need to do to change over?
For example, while I have made the alias python=python3, I don't know about the modules I've installed with pip. I was using a version of pip for Python 2, but does that mean modules were written for Python 2 and not 3? Do I now need to start using pip3 (or make a corresponding alias pip=pip3 or pip=pip3.5)? If modules were installed using the command pip, does that mean I have to reinstall them for Python 3 using pip3? If I do need to reinstall them for 3, should I start removing them from my Python 2 env as cleanup?
And another question that seems like it may entail a lot of work: How should I change all my virtual environments for Python projects? They were all Python 2 envs, and now I'm not sure whether it's necessary, useful, or possible to reinstall or upgrade the modules within them to the corresponding ones for Python 3.
Sorry if this seems like a duplicate question - I've searched and only found resources regarding "how to upgrade" rather than "what to do after upgrading". Thanks for your help!
It is strongly recommended not to symlink python to Python 3, at least on Debian-based Linux distros. Debian utility scripts use both Python 3 and 2.7 to work (which means you already had a copy of Python 3 somewhere...), and as a consequence Debian-based distributions ship both versions. Symlinking can cause unexpected breakages. This may or may not be true on other systems, however, but with such ambiguity it is probably useful not to try.
Instead, live with symlinking python3 to Python 3. Leave python alone.
pip is usually symlinked to the corresponding pip program for 2.7. Use pip3 to specify you want to use the pip program for Python 3. If you use pip, you'll find modules for Python 3 being installed to Python 2.7 site directories and nothing will work as you expect it to. There should be no reason why you can't symlink pip to pip3, but I'd still not recommend it - it's better to tread cautiously in this regard.
You don't need to change your current virtual environments. Just create new ones with virtualenv, pointing to the correct Python program to use. This is the whole point of virtual environments: to sandbox different Python versions, so that neither of them adversely interact with each other.
If you have projects you really want to ship to Python 3, I'd recommend using a version control system to back up your current files, and then reproducing them in a new virtual environment configured for Python 3. This is quick, simple and painless.

hostgator - change python version

I opened a ticket with hostgator but trying to fix this on my own.
On my shared hostgator account, when I do python -V. It gives me 2.6.6
I need to use 2.7 which they do have, but doesn't work on my shebang line.
1)So, how do I change my python command to point to 2.7
I tried modifying the .bash_profile but the 2.7 path is added at the end.
2)Actually my shebang line needs to work as well.
I found the below comment for the same problem posted by someone else on Google Groups. I am also experiencing the same problem, but haven't yet tried the below mentioned approach yet. Please try if you find it might help.
Google Groups link
Hi, I'm also using hostgator to host a django project.
first of all note that they have different plans with different features, what I'm going to write applies to their shared hosting plans.
Looks like they are using some version of centos, which comes with python 2.6 I believe.
Installing a python from source on your home folder is a good idea, but unfortunately hostgator blocks access to gcc.
on the other hand they already have python 2.7.3 installed, juts use python2.7 as the executable, try running "python2.7 -V"
btw, they also have python2.6 for 2.6.6 and python3 for 3.2.3
after that you should use virtualenv to create a project specific env so you can install things using pip. download the virtualenv.py file to you project folder and run it from there. for the index.fcgi file you should put this in the first line:
#!/home/username/projectname/env/bin/python
other than that I think it should be standard

Updating Python for use with AWS CLI

I'm trying to use AWS CLI S3 within the Terminal (Mac OS X v10.6.8) and after configuring all of the proper credentials when I run basic commands (e.g., aws s3 ls) it does not output anything.
When I do a slightly more complicated command (e.g., aws s3 mb s3://newbucketname) it outputs: __init__() keywords must be strings.
Based on some research I suspected the cause is that Python 2.6.1 is installed by default, so I downloaded v3.3.2, installed it, and used the 'Update Shell Profile.command' feature to set the correct PATH variable.
Now with the new version of Python installed and configured I still get the same results. The Terminal still appears to be using the old version of Python, despite the $PATH variable pointing to the new version (v3.3.2).
Any help would be greatly appreciated. I'm guessing that it has to do with the Terminal not using the new version of Python and thus the AWS CLI functionality doesn't work, but there may be a different cause that I'm not aware of.
Thank you!
If you installed aws with the easy_install that came with Python 2.6, it will be hardcoded to use Python 2.6—its first line will be something like this:
#!/usr/bin/python2.6
This shebang line means that the script will run with /usr/bin/python2.6. Installing Python 3.3 won't change what's at /usr/bin/python2.6. It has nothing to do with what's on the PATH, or what the first thing called python is on the PATH. The PATH only comes into play if a script uses /usr/bin/env on the shebang line. And /usr/bin/env python2.6 would of course still find Python 2.6. In fact, even /usr/bin/env python would still find Python 2.6, because 3.3 doesn't have anything named python, just python3.
Meanwhile, even if you managed to hack it up to run with Python 3.3 instead (e.g., by changing that first line to /Library/Frameworks/Python.framework/Versions/3.3/bin/python3.3 or /usr/bin/env python3), that would just make it break completely. The aws script requires the aws package to be installed into your site-packages. You've installed them into your 2.6 site-packages, but not your 3.3 site-packages. (On top of that, many packages install different code for Python 2.x vs. 3.x, so the 2.6 script might not work with the 3.3 package even if it were there.)
Anyway, the right way to fix this is to uninstall aws from Python 2.6, and re-install it for Python 3.3.
If you'd used pip as recommended, this would be trivial:
pip-2.6 uninstall awscli
pip-3.3 install awscli
Unfortunately, because you used easy_install instead, you have to uninstall it manually.
And really, you don't need to uninstall the packages, just the scripts that ended up in /usr/local/bin or somewhere else on your PATH. I suspect rm /usr/local/bin/aws* will take care of that, but be careful—make sure there's nothing else installed there that starts with aws but isn't part of the package.
Meanwhile, for the future, install pip and use that. For Apple's Python 2.6, use sudo easy_install pip to install it. For Python 3.3, follow the instructions at the pip site.

Python + Leopard + Fink + Mac Ports + Python.org + Idiot = broken Python - fresh start?

I have been enjoying learning the basics of python, but before I started reading things I tried to install various python versions and modules clumsily. Now that I have some ideas of what I want to do and how to do it I'm finding that various aspects are broken. For instance, 2.6 IDLE won't launch, and when I try to import modules they usually don't work.
My question is, how would you recommend I clean this up and start fresh? I have read information about modifying the 2.6 install, but I still can't get it to work.
IDLE 2.4 works, and when I launch python from the terminal I am running python 2.4.4.
I had this problem so much when I first got my Mac. The best solution I found was to delete everything I'd installed and just go with the pythonmac.org version of Python (2.6). I then installed setuptools from the same site, and then used easy_install to install every other package.
Oh, and I got the GNU C Compiler from the Xcode developer tools CD (which you can download from Apple's website), so that I can compile C extensions.
Macports should be easy to get rid of; just delete /opt/local/. I think that Fink does something similar.
You can do which python to see what python is the default one. The system python should be in /System/Library/Frameworks/Python.framework/Versions/2.5/bin/python
The MacPython you may have downloaded would either be in /Library/Frameworks/Python.framework. You can delete this as well.
Also, both MacPython and MacPorts edit your ~/.profile and change the PYTHONPATH, make sure to edit it and remove the extra paths there.
The easiest way to start afresh with Mac Ports or Fink is to simply remove the folder /sw/ (for fink) or /opt/ for MacPorts.
To completely remove them, you will have to remove a line in your ~/.profile file:
For fink:
test -r /sw/bin/init.sh && . /sw/bin/init.sh
..and for MacPorts, I don't have it installed currently, but there will be something along the lines of:
export PATH=$PATH:/opt/local/bin
export PATH=$PATH:/opt/local/sbin
As for installing Python, currently the cleanest way is to build it from source..
I wrote up how I installed Python 2.6 on Leopard here. It was for one of the 2.6 beta releases, so change the curl -O line to the newest release!
In short, download and extract the latest python 2.6 source tarball, then (in a terminal) cd to where you extracted the tarball, and run the following commands..
./configure --prefix=/usr/local/python2.6
make
sudo make install
That will install python2.6 into /usr/local/python2.6/ (the last line requires sudo, so will ask you for your password)
Finally add /usr/local/python2.6 to $PATH, by adding the following line you the file ~/.profile
export PATH=$PATH:/usr/local/python2.6
Then you will be able to run the python2.6 command.
Ideally you would just install MacPython, but it doesn't seem to have a decent Python 2.6 installer yet.

Categories