1

Edit:

So now which pip, which python and which python3 have started working correctly somehow. I was also able to install libraries using pip. The only remaining problem is that of the apt_pkg. Running apt-get install python-apt gives:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-apt is already the newest version (1.6.3ubuntu1).

Running any python application still gives error: ImportError: No module named apt_pkg

Running echo $PATH returns:

/home/hamza/bin:/home/hamza/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

Running find /usr -name python -o -name python3 returns:

/usr/local/lib/python3.5/dist-packages/notebook/static/components/codemirror/mode/python
/usr/local/lib/python2.7/dist-packages/notebook/static/components/codemirror/mode/python
/usr/lib/python3
/usr/lib/gimp/2.0/python
/usr/lib/libreoffice/share/Scripts/python
/usr/lib/virtualbox/sdk/bindings/xpcom/python
/usr/lib/wx/python
/usr/bin/python
/usr/bin/python3
/usr/share/code/resources/app/extensions/python
/usr/share/bash-completion/helpers/python
/usr/share/bash-completion/completions/python
/usr/share/bash-completion/completions/python3
/usr/share/python
/usr/share/javascript/codemirror/mode/python
/usr/share/python3
/usr/share/lintian/overrides/python
/usr/share/lintian/overrides/python3
/usr/share/gcc-8/python
/usr/share/gdb/python
/usr/share/librevenge/python
/usr/share/doc/python
/usr/share/doc/python3
/usr/share/doc/python-statsmodels/examples/python
/usr/share/playonlinux/python

Original:

Python on my system is a wreck. I have got multiple versions installed. None work properly. Apparently some applications using python are not working either (eg: Unity Tweaks). My python libraries will not install because pip doesn't work, although it says it is already installed

I was trying to install some libraries for python on my system using pip. Turned out pip was not working. I tried to reinstall pip only to learn that pip was already installed. I went through a process of understanding the difference between python and python3. I have tried enough things and have basically lost track of the things I have done to get the libraries installed. Long story short, pip does not work no matter what, my libraries will not install and consequently my code doesn't run.

Here is some of the things I have already done:

which pip

This return no output

apt-get install python-pip  

Says I have pip already installed

apt-get install python-apt

To resolve ImportError: No module named apt_pkg. It says:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
python-apt is already the newest version (1.6.3ubuntu1).

But the error persists

And countless other stuff I do not remember.

What I want now is simple. I wish to somehow get out of this hassle by resetting all of my python settings and installation to default, and then install the pandas and numpy libraries for my system. Any and all help would be appreciated.

Result for python -m pip -V:

pip 9.0.1 from /usr/lib/python2.7/dist-packages (python 2.7)

Result for python3 -m pip -V:

pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)
Syed H
  • 270
  • 1
  • 3
  • 13
  • Show us the results from `python -m pip -V` and `python3 -m pip -V`. – John Anderson Apr 13 '19 at 15:44
  • try this: `sudo apt-get install python-apt` – Mojtaba Kamyabi Apr 13 '19 at 15:45
  • @JohnAnderson Edited question and added results above – Syed H Apr 13 '19 at 15:55
  • Sounds like you simply wrecked your `PATH`. Without more information about what you have installed and where, I don't think we can tell you what's wrong. – tripleee Apr 13 '19 at 15:55
  • @shotgunner I have already done so. It does not resolve the problem. The apt_pkg issue remains – Syed H Apr 13 '19 at 15:56
  • @tripleee Isn't there a way to resolve it by somehow resetting python to system default? – Syed H Apr 13 '19 at 16:03
  • It might be as easy as finding out what you did with your `PATH` and reverting that. It might be more complex than reinstalling your system. Because we don't know what's wrong, we can't say what it takes to fix it. – tripleee Apr 13 '19 at 16:07
  • @tripleee How do I find out what I have done to my `PATH`? – Syed H Apr 13 '19 at 16:19
  • Odd that `python` and `python3` are in your path, but not `pip`. You can check your path with `echo $PATH`. Try `sudo python -m pip install --upgrade --no-deps --force-reinstall pip` and `sudo python3 -m pip install --upgrade --no-deps --force-reinstall pip`. – John Anderson Apr 13 '19 at 17:11
  • Maybe for a start [edit] the question to explain in more detail what you have installed where and how. The output of `echo "$PATH"` and `find /usr -name python -o -name python3` would be useful to help us see at least some basic diagnostics. – tripleee Apr 13 '19 at 17:25
  • @tripleee Apologies for the delay. I've updated the question. The edit is at the top. – Syed H Apr 14 '19 at 10:14
  • Do you have any Python stuff in `/home/hamza/bin`, `/home/hamza/.local/bin`, or `/snap/bin`? – tripleee Apr 14 '19 at 10:26
  • `/home/hamza/bin` does not exist. `/home/hamza/.local/bin` has got several pip files such as `pip`, `pip2`, `pip3` and some jupyter files. `/snap/bin` has got several pycharm and anbox files – Syed H Apr 14 '19 at 10:53

1 Answers1

-1

One of the following commands worked for me:

pip3 install -U pip
python -m pip install -U pip
python3 -m pip install -U pip

Make sure the version of your python3 is 3.6, which is the default version of ubuntu18, then upgrade pip.

export py3_path=`which python3`
rm $py3_path
ln -s `which python3.6` $py3_path
python3 -m pip install -U pip

Or use pyenv to manage multi versions https://github.com/pyenv/pyenv

Waket Zheng
  • 5,065
  • 2
  • 17
  • 30
  • the first command gives me multiple (ImportError: No module named 'apt_pkg') errors. The second two tell me (Successfully installed pip-19.0.3) – Syed H Apr 13 '19 at 15:58
  • which pip still gives out (ImportError: No module named 'apt_pkg') errors – Syed H Apr 13 '19 at 16:00
  • @SyedH why the version of your python is 3.5? You installed by yourself? – Waket Zheng Apr 13 '19 at 16:05
  • 1
    I'm not sure. I've got 3, 3.5, 3.6, 3.7 and probably several others. I am not sure how or when I installed them, but it was possibly installed as a result of following a stack overflow answer. – Syed H Apr 13 '19 at 16:17