1
votes

I'm very new to python but I've learned the basics and now how it mostly works. I've been trying to install a Django framework for a server so that it can host a webpage.

Basically the problem here is that when I run commands such as:

python3 -V

I get the output

Python 3.6.1

But for some reason when using pip3 it decides to use the pip that is version specific to Python 3.5, for example doing:

pip3 install Django==1.11

installs Django in "/usr/local/lib/python3.5/dist-packages" instead of the Python 3.6 counterpart of the dist-packages directory.

according to python documentations (https://docs.python.org/3/installing/index.html?highlight=pip#work-with-multiple-versions-of-python-installed-in-parallel) I should be able to run this command:

python3.6 -m pip install SomePackage

to use the pip that is specific to Python 3.6, but this doesn't seem to work. I get an error saying "no module named pip" or "no module named pip3".

I am running on a server that uses Ubuntu 16.04

I appreciate all help, thanks in advance! :)

EDIT: I have tried running

pip3 -V

which gave me the output

pip 9.0.1 from /home/user/.local/lib/python3.5/site-packages (python 3.5)

From this I can say that I have no problems at all using python3 with Python 3.6, but when running pip3 it uses pip 9.0.1 from Python 3.5. Also running

sudo apt-get install python3-pip

gives me the output

0 upgraded, 0 newly installed, 0 to remove and 98 not upgraded.
2
can you type which python command?Eliethesaiyan
@Eliethesaiyan There is no problems with using any python3 commands, python3 -V proves that. But it's the pip3 specific for 3.6 that I have problems with.DarkCatapulter
python3.6 can assert itself as the one to be used by pip with this command: python3.6 -m ensurepip --default-pip then you can do a pip3 install SomePackage then the files go to the right place.Eric Leschinski

2 Answers

0
votes

I once had the similar problem. And, I sort it out with following:

  1. First install pip3 in your system

     sudo apt-get install python3-pip
    
  2. Create your virtualenv

     pip3 -p python3.6 virtualenv myenv
    
  3. Then install djangon in your virtualenv after activating it.

     pip3 install Django
    

You can specify the django version as:

  pip3 install Django==1.11
0
votes

I totally forgot about this post, I just wanna say that pip is a very dangerous tool and should be used with caution since it affects the structure of your computer/server. What I did to solve whatever mess I had created at this time was to:

  1. Format the server.

  2. To work with and only use pip/pip3 in virtualenv. What makes virtualenvs so awesome is that if something goes wrong then it only goes wrong inside that virtualenv. You will not need to format your computer/server, instead you might have to delete that virtualenv and create a new one.

  3. Never use pip/pip3 on your computer/server without a virtualenv, I found out that you don't even need to install it on your root. Best way of using pip is to run a virtualenv and then install it on that virtualenv.

Hope these tips helps preventing people from making huge but easily avoidable mistakes! :D