1

I installed python3.5.2 from my home directory from a tar. (I remember using an atlinstall command)

Then, I installed django using pip3, by doing sudo -H pip3 install django, and the installation was successful.

I also installed numpy, scipy, some other modules.

All these modules are accessible when I am using python3.5 as the command from the command line, but I am not able to import these modules when I call python3.

And, all the third party software is also using this python3, as a result I am not able to use any GUI to import any of the modules mentioned.

My question is, how I can get the other python3 to point to the same thing as python3.5 which has all the modules installed.

salman@Skynet ~]$ python3
Python 3.5.2 (default, Nov 17 2016, 17:05:23) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'django'
>>> exit()
[salman@Skynet ~]$ python3.5
Python 3.5.2 (default, Nov 30 2016, 11:30:08)   
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> 

It works when python3.5 is used.

Edit: Requested outputs

which python3 python3.5:

/usr/bin/python3
/usr/local/bin/python3.5

env | grep -i python; for p in $(ls /usr{,/local}/bin/python3*); do echo -- $(ls -l $p); $p -c "import sys; print(sys.path)"; done

-- lrwxrwxrwx 1 root root 9 Mar 23 2016 /usr/bin/python3 -> python3.5
    ['', '/usr/lib/python35.zip', '/usr/lib/python3.5',  '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib-  dynload', '/usr/local/lib/python3.5/dist-packages',  '/usr/lib/python3/dist-packages']
-- -rwxr-xr-x 2 root root 4460336 Nov 18 01:23 /usr/bin/python3.5
    ['', '/usr/lib/python35.zip', '/usr/lib/python3.5',  '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib- dynload', '/usr/local/lib/python3.5/dist-packages',   '/usr/lib/python3/dist-packages']
-- -rwxr-xr-x 2 root root 4460336 Nov 18 01:23 /usr/bin/python3.5m
    ['', '/usr/lib/python35.zip', '/usr/lib/python3.5',  '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib- dynload', '/usr/local/lib/python3.5/dist-packages',   '/usr/lib/python3/dist-packages']
-- lrwxrwxrwx 1 root root 10 Mar 23 2016 /usr/bin/python3m ->  python3.5m
    ['', '/usr/lib/python35.zip', '/usr/lib/python3.5',  '/usr/lib/python3.5/plat-x86_64-linux-gnu', '/usr/lib/python3.5/lib- dynload', '/usr/local/lib/python3.5/dist-packages',  '/usr/lib/python3/dist-packages']
-- -rwxr-xr-x 2 root root 12170760 Nov 30 11:30   /usr/local/bin/python3.5
    ['', '/usr/local/lib/python35.zip', '/usr/local/lib/python3.5',  '/usr/local/lib/python3.5/plat-linux', '/usr/local/lib/python3.5/lib- dynload', '/usr/local/lib/python3.5/site-packages']
-- -rwxr-xr-x 2 root root 12170760 Nov 30 11:30  /usr/local/bin/python3.5m
    ['', '/usr/local/lib/python35.zip', '/usr/local/lib/python3.5',  '/usr/local/lib/python3.5/plat-linux', '/usr/local/lib/python3.5/lib- dynload', '/usr/local/lib/python3.5/site-packages']
-- -rwxr-xr-x 1 root root 3080 Nov 30 11:31  /usr/local/bin/python3.5m-config
Usage: /usr/local/bin/python3.5m-config --prefix|--exec-prefix|--  includes|--libs|--cflags|--ldflags|--extension-suffix|--help|--abiflags|--    configdir

Also, how can I delete the python3.5 from the /usr/local/bin without harming the python3 in /usr/bin?

Thank you everyone for reading the question and answering.

Zanna
  • 70,465
Skynet094
  • 121
  • 1
    Could you please tell the output of which python3 and which python3.5? – michael Nov 30 '16 at 09:25
  • 1
    which python3 -> /usr/bin/python3,
    which python3.5 -> /usr/local/bin/python3.5
    – Skynet094 Nov 30 '16 at 09:29
  • I don't know why the pip3 installs modules into python3.5's location. However, I understand now what was the problem, thanks! – Skynet094 Nov 30 '16 at 09:31
  • 1
    @SalmanEstyak, nevermind, try this one in single command (copy/paste/run) env | grep -i python; for p in $(ls /usr{,/local}/bin/python3*); do echo -- $(ls -l $p); $p -c "import sys; print(sys.path)"; done – user.dz Nov 30 '16 at 10:32
  • If you are installing a different version of Python for working with Django, consider using virtualenv. Never change Python for the whole system because you can mess with synaptic scripts. http://askubuntu.com/questions/244641/how-to-set-up-and-use-a-virtual-python-environment-in-ubuntu – JP Ventura Nov 30 '16 at 13:08
  • The question does not have to do with django specifically, it's a ubuntu question. . Btw, I am using pyvenv for virtual environment. :) – Skynet094 Nov 30 '16 at 15:50
  • 2
    @SalmanEstyak The real question here is why you installed Python 3 again in addition to the Python 3 that already comes with Ubuntu. Unless you have good reasons to do this, it is not worth the effort as you can tell from your own question. – edwinksl Nov 30 '16 at 15:52
  • You are right. I did not know that the ubuntu already has the latest version of python, I should have checked. – Skynet094 Nov 30 '16 at 15:56
  • 1
    @user.dz: echo -- $(ls -l $p) – why? It could be simply ls -l "$p" (with added quotation to avoid escaping issues). – David Foerster Nov 30 '16 at 18:38
  • @DavidFoerster, :) I forget what I was trying to do with echo before I changed it into that twisted shape. echo; ls -l $p could enough to get a readable output, I don't expect any executable have space in filename. – user.dz Nov 30 '16 at 18:53

1 Answers1

1

One solution -- although to be considered carefully -- is to have python3 point to the python3.5 which works correctly:

sudo mv /usr/bin/python3 /usr/bin/python3_backup
sudo ln -s /usr/local/bin/python3.5 /usr/bin/python3 

Update: Other method

My first answer was in the case you were sure you needed the python3.5 in /usr/local/bin. If that's not the case and you want to keep the system python 3 while adding modules from your /usr/local python3.5, you can simply update your PYTHON_PATH variable as follows in your bashrc (as according to the outputs you provided):

export PYTHONPATH=${PYTHONPATH}:/usr/local/lib/python3.5:/usr/local/lib/python3.5/plat-linux:/usr/local/lib/python3.5/site-packages
Zanna
  • 70,465
michael
  • 254
  • 1
  • 9
  • 1
    Never mess with the Python used by the system. The software update manager uses Python 3, so you are jeopardizing your workstation. – JP Ventura Nov 30 '16 at 13:06
  • @JPVentura This is true, but in this case python3.5 is a python 3 interpreter. And this is actually how it is configured in a vanilla version of Ubuntu (python3 pointing to python3.5) – michael Nov 30 '16 at 13:31
  • The pip3 was not working when I simply changed the pointer. I had to revive the backup to fix that. :( – Skynet094 Nov 30 '16 at 15:47
  • I am guessing that the python3 for the system has access to a lot more modules than python3.5 which is in the usr/local/bin. – Skynet094 Nov 30 '16 at 15:51