简体   繁体   English

如何在 Ubuntu 18.04 中将 Python 的所有内容完全重置为默认值?

[英]How to completely reset everything Python to default in Ubuntu 18.04?

Edit:编辑:

So now which pip , which python and which python3 have started working correctly somehow.所以现在which pipwhich pythonwhich python3以某种方式开始正常工作。 I was also able to install libraries using pip.我还能够使用 pip 安装库。 The only remaining problem is that of the apt_pkg.唯一剩下的问题是apt_pkg。 Running apt-get install python-apt gives:运行apt-get install python-apt给出:

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运行任何 python 应用程序仍然会出现错误: ImportError: No module named apt_pkg

Running echo $PATH returns:运行echo $PATH返回:

/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:运行find /usr -name python -o -name python3返回:

/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.我系统上的 Python 一团糟。 I have got multiple versions installed.我安装了多个版本。 None work properly.没有一个工作正常。 Apparently some applications using python are not working either (eg: Unity Tweaks).显然,一些使用 python 的应用程序也不起作用(例如:Unity Tweaks)。 My python libraries will not install because pip doesn't work, although it says it is already installed我的 python 库不会安装,因为 pip 不起作用,尽管它说它已经安装了

I was trying to install some libraries for python on my system using pip.我试图使用 pip 在我的系统上为 python 安装一些库。 Turned out pip was not working.原来 pip 不起作用。 I tried to reinstall pip only to learn that pip was already installed.我试图重新安装 pip 只是为了了解 pip 已经安装。 I went through a process of understanding the difference between python and python3 .我经历了一个理解pythonpython3之间区别的过程。 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.长话短说,无论如何 pip 都不起作用,我的库将无法安装,因此我的代码无法运行。

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说我已经安装了 pip

apt-get install python-apt

To resolve ImportError: No module named apt_pkg .解决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.我希望通过将所有 python 设置和安装重置为默认值,然后为我的系统安装 pandas 和 numpy 库,以某种方式摆脱这种麻烦。 Any and all help would be appreciated.任何和所有帮助将不胜感激。

Result for python -m pip -V : python -m pip -V结果:

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

Result for python3 -m pip -V : python3 -m pip -V结果:

pip 9.0.1 from /usr/lib/python3/dist-packages (python 3.5)

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.确保你的python3的版本是3.6,这是ubuntu18的默认版本,然后升级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或者使用pyenv管理多版本https://github.com/pyenv/pyenv

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM