"python -m django --version" 1.11.18 Cannot update to 2.1 - django

I watched a tutorial that requires me to have Django 2.1.
When I type in "python -m django --version" - my Ubuntu terminal says 1.11.18 But, when I type "django-admin --version" - terminal says 2.1 This didn't bother me until I reached part 6 of this series, I'm heavily invested now with a serious problem I can't figure out. I even completely reinstalled my OS, (I was running Linux mint, thought it'd be easier if I ran Ubuntu) I ran through a myriad of different "fixes" I found online, but nothing seemed to fix this.
The main issue that I ran into from the tutorial is the urls linking.
EDIT:
I have Python 3.6 installed

You need to be using Python-3 to use Django-2.1. Django 1.11 is the last version to support Python 2.7.

The problem is most likely because you've got both Python 2 and Python 3 installed on your system, and you're installing Django without a virtual environment. I would highly recommend using a virtual environment: it keeps your project separated from the system Python version's packages. At this point, using Python 3 and venv to make your virtual environment is the best practice.
See the documentation here: https://docs.python.org/3/library/venv.html#creating-virtual-environments
Here's a quick walkthrough to create a new virtual environment in a directory called "my_django_project" in your home directory with Python 3 and install Django:
python3 -m venv ~/my_django_project
pip install Django
. ~/my_django_project/bin/activate
To deactivate your virtual environment, type deactivate.
Then, whenever you want to work on this project, type . ~/my_django_project/bin/activate.
Now let's say you wanted to work on a separate project using another Python package, like OpenCV. You could create a separate virtual environment for this project:
python3 -m venv ~/my_opencv_project
pip install opencv
. ~/my_opencv_project/bin/activate
This allowed you to keep your projects separate. There is a fair amount more to learn, but this should be enough to get you started. Good luck!

Related

Anaconda Update - UNDESIRED Revert to Earlier Version

I am running anaconda on OS 10.11.6. I am not certain of the precise anaconda version that I previously had, but it was about 4-6 months old, I believe, and it was running Python 2.7.11. I wanted to update both python (to 2.7.12) and anaconda (while I was at it) and so I used the standard procedure of
conda update conda
conda update anaconda
This has worked swimmingly for me in the past. This time, however, it is taking me back to an earlier version of python (2.7.10) when I do this. From running conda --version I see that I have conda 4.1.11, which is the latest, as I understand it. However, when I run conda update anaconda I get a display saying:
anaconda 2.3.0 np19py27_0
Similarly, with python --version I get:
Python 2.7.10 :: Anaconda 2.3.0 (x86_64)
In my folder ~/anaconda/bin/ (which folder I also have in my PATH such that calls to python direct here) I have an alias named python which says that it was just updated today (which is when I ran the conda update, etc.). But, it just points to a file python 2.7 which is ins ~/anaconda/ and hasn't been modified since May 2015.
I figure if I did a complete uninstall and reinstall of anaconda, I could presumably clear this up. I'd rather avoid that if possible though, since it would mean reinstalling all the rest of my other python packages, etc.
I also saw this SO Post: Anaconda not updating to latest . but when I try:
conda install anaconda=4.1.1
I get the following error:
Fetching package metadata .......
Solving package specifications: ....
The following specifications were found to be in conflict:
- anaconda 4.1.1*
- gevent-websocket -> gevent 0.13.7|0.13.8|1.0|1.0.1|1.0.2|1.1.0
- gevent-websocket -> python 2.6*
Use "conda info <package>" to see the dependencies for each package.
Update: I ended up just wiping my old installation and installing a fresh version of Anaconda. It was a bit of a pain but it seemed like it would be less work than trying to track down what was happening with this bug. Still though, I'd be delighted in any solutions people have to this issue for future reference by me and others who encounter this.

New point of view: pip dealing with multiple Python versions, Canopy, Anaconda on Linux

Using pip with different Python version is a common problem, as I see when I search the Internet. There are a lot of answers around, also in this forum. However nobody seems to encounter the same problem that I have:
I use Canopy python most and it was installed first. Later I installed Anaconda. Now when I try to install a program with pip it always install it in Canopy (or refuse to install it because it is already installed in Canopy.
for example:
$ pip install ipython
gives:
Requirement already satisfied...
but there are no ipython in my Anaconda-folder, it is in the /Enthought/Canopy_64bit/... folder
How can I overcome this problem?
Both versions are 2.7 and even if one is 2.7.11 and the other 2.7.12, it did not work to distinguish between the two by this.
Maybe you can try the following.
Find where both pip-s reside (whereis pip, I have it on ~/anaconda2/bin), then cd to the pip directory of the python version you want, and execute it from there.
I manage with the help of J. Corson comment:
When you want to use a particular Python installation, activate the desired environment. In my chase
source /home/per/anaconda_ete/bin/activate
then using pip made the installation in the anaconda python and I could install ipython and other stuff there... fine, thanks!

Python site-packages and corresponding interpreter

I used brew to install python 2.7 and 3.5 on Mac. SOMEHOW I have this site-packages directory /usr/local/lib/python2.7/site-packages.
But every python interpreter on the system points to every other site-packages directory EXCEPT this one. How do I use THIS site-packages directory?
(This is all because I need Vips. I'd installed this before, but now I'm using a different machine and I can't figure out how on Earth I got it to work before.)
The vips docs have a checklist and an explanation of what happens when Python tried to import vips:
http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/using-from-python.html
But briefly you need to:
You have several Pythons installed, make sure you are invoking the brew one.
Make sure that that Python has a gi repository containing the Vips.py overrides.
Make sure you have a Vips-8.0.typelib file in /usr/local/lib/lib/girepository-1.0/.
SOLVED.
I didn't want to have to resort to resetting my dev box to factory settings, but I did. I hope this helps somebody...
If Python already exists on your system, and you're planning on installing Python yourself or with Homebrew (because you only get python2.7 out of the box), make sure you install the new Python first. Then put the install location first in your PATH. Then install your modules. In that order. I knew something was wrong, so I uninstalled Python/3 and Vips. But when I reinstalled them, for whatever reason Vips still didn't know to bind itself to the Python in /usr/local/Cellar. Even though I had /usr/local/Cellar first in PATH.
So to recap -- first install Homebrew, then set the PATH, then install python/python3, and finally install Vips. And you're good to go.

too many pythons on linux

i recently started using python with xubuntu on virtualbox but i'm having problems. I want to be able to use numpy so i thought that apt-get install python-numpy would solve everything, but using the shell i kept getting No module named numpy. I used IDLE and it could find it. I also have IDLE (using Python-2.7), and again it could import numpy. Then i noticed that the shell had python 2.7.9, while the IDLEs had python 2.7.6.
Using
import sys
print sys.path
this if what i get from 2.7.9 (shell)
/usr/local/lib/python2.7/site-packages/setuptools-17.0-py2.7.egg
/usr/local/lib/python2.7/site-packages/Pillow-2.3.0-py2.7-linux-x86_64.egg
/usr/local/lib/python2.7/site-packages/mock-1.0.1-py2.7.egg
/usr/local/lib/python27.zip
/usr/local/lib/python2.7
/usr/local/lib/python2.7/plat-linux2
/usr/local/lib/python2.7/lib-tk
/usr/local/lib/python2.7/lib-old
/usr/local/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/site-packages
and from 2.7.6 (IDLE)
/home/alessandro
/usr/bin
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages/PILcompat
/usr/lib/python2.7/dist-packages/gtk-2.0
/usr/lib/pymodules/python2.7
/usr/lib/python2.7/dist-packages/ubuntu-sso-client
I understand that i have two versions of python installed and somehow i ended up installing packageg into only one of them (the 2.7.6).
I'd like to be able to use 2.7.9 both in the shell and in IDLE and also i'd like to install so that python 2.7.9 can see them.
I read that i can add paths to the python sys.path, but isn't there a more efficient/persistent way to do what i want?
PS: tell me if you need more informations
For my projects I usually create a virtualenv for each python version I need for the project at hand. I manage them using pip to install specific versions that I need. Moreover you should be able to choose the python path in your IDE. While I'm not using IDLE, I read here that apparently idle comes along with the python versions during install. So maybe your idle versions collide with each other. If you want to have only one python version at the time on your machine you might consider a simple remove and fresh install of your desired version. Again I would recommend pip over apt-get etc. Hope this is of help for you.
Worth to check PyDev, a plugin for Eclipse to work on python.
http://marketplace.eclipse.org/content/pydev-python-ide-eclipse , or http://pydev.org/.
This allows you to configure the python version for different project's.
I have some project's with python 2.7 and others with 3.4.
it's checks the whole system in search for the PYTHONPATH to use!

How can I remove a version of Python in Ubuntu 12.04?

I have just installed Ubuntu 12.04 which comes with Python 2.7. I have installed Python 3.3, so now I have both versions. For example, if I type python in the terminal I get version 2.7 and if I type python3.3 I get that version.
I don't see why I would need 2 versions (?) so how do I uninstall Python 2.7? And if I do so, will the "python" command then point to Python 3.3?
VERY IMPORTANT EDIT
Removing an older version of python may be very dangerous and can cause trouble in your whole system! For your case instead of removing the older python you can simply use an alias in your terminal, so that when you type python it opens python3.3;
Here is the procedure, add this line:
alias python=python3
Into~/.bash_aliases or: ~/.bashrc
Btw I guess If you ask this question in AskUbuntu you may have a quicker/better response!
You should never remove the builtin Python in your Ubuntu distribution. Bad things will happen if you do.
It is highly recommended to use virtualenv to install other Python environments.
Here's a good Stackoverflow question that demonstrates how:
Is it possible to install another version of Python to Virtualenv?