Python:没有命名的模块......如何使用pip

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35103338/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 15:59:42  来源:igfitidea点击:

Python: No module named ... How to use pip

python

提问by onigiri

I'm a new to Python, and I have a trouble in import library.

我是 Python 新手,在导入库时遇到了麻烦。

I wrote a code

我写了一段代码

from sklearn.linear_model import LogisticRegression

then I got an error

然后我得到了一个错误

ImportError                               Traceback (most recent call last)
<ipython-input-19-c84b03903d9e> in <module>()
----> 1 from sklearn.linear_model import LogisticRegression

/usr/lib/python2.7/dist-packages/sklearn/linear_model/__init__.py in <module>()
     10 # complete documentation.
     11 
---> 12 from .base import LinearRegression
     13 
     14 from .bayes import BayesianRidge, ARDRegression

/usr/lib/python2.7/dist-packages/sklearn/linear_model/base.py in <module>()
     22 
     23 from ..externals import six
---> 24 from ..externals.joblib import Parallel, delayed
     25 from ..base import BaseEstimator, ClassifierMixin, RegressorMixin
     26 from ..utils import as_float_array, atleast2d_or_csr, safe_asarray

/usr/lib/python2.7/dist-packages/sklearn/externals/joblib/__init__.py in <module>()
      1 # yoh: use system-wide joblib
      2 
----> 3 from joblib import *

ImportError: No module named joblib

in IPython. I'm using ubuntu and I installed scikit_learn-0.18 by using "sudo apt-get install python-sklearn" command but encountered above error. I also tried to use "sudo easy_install joblib" but the error was not erased.

在 IPython 中。我正在使用 ubuntu,我使用“sudo apt-get install python-sklearn”命令安装了 scikit_learn-0.18,但遇到了上述错误。我也尝试使用“sudo easy_install joblib”,但错误没有被删除。

What is wrong? Would you help me? Thank you.

怎么了?你能帮我吗?谢谢你。

采纳答案by Lo?c

pip is python's packet manager. It's shipped by default with python since version 3.4, so you should probably use it.

pip 是 python 的数据包管理器。自 3.4 版以来,它默认随 python 一起提供,因此您可能应该使用它。

Usually for now, pythonon linux redirects to python2.7and there is kind of a problem with upgrading to python3.x because of some old linux tools.

通常现在,python在 linux 上重定向到python2.7并且由于一些旧的 linux 工具升级到 python3.x 存在某种问题。

So you'll probably have both python2.7 and python3.x on your OS at some point.

因此,在某个时候,您的操作系统上可能会同时拥有 python2.7 和 python3.x。

If you aren't sure if you have pip for the version of python you want to use install it :

如果您不确定是否有要使用的 python 版本的 pip 安装它:

cd /tmp
wget https://bootstrap.pypa.io/get-pip.py
python3.4 get-pip.py # install pip for any python -v (3.4 here but replace with yours)
rm get-pip.py -f

Now pip is installed, and you can use it to search / install / upgrade / remove / ... python packets.

现在pip已经安装好了,你可以用它来搜索/安装/升级/删除/...python数据包。

So let's install joblib :

所以让我们安装 joblib :

python3.4 -m pip install joblib # install packets for a particular version easily

As you can see I don't use pip installbut python3.x -m pip installso pip installs the libraries for that specific version of python.

正如您所看到的,我不使用pip installpython3.x -m pip install因此 pip 会为该特定版本的 python 安装库。

回答by sardylan

The Python way to install dependencies is pip, but I prefer to use OS official dependencies when available to avoid loosing compatibilty and updates related to OS package manager. In Ubuntu there are a lot of python packages which have two different versions: one for Python 2.7 and one for Python 3.4. First of all try to install joblib searching for python3-joblibpackage name for python 3 or python-joblibfor python 2. If your version of Ubuntu still not have the required dependency you can use pip (pip2.7 or pip3.4, both available as python-pipand python3-pippackages).

Python 安装依赖项的方式是 pip,但我更喜欢在可用时使用 OS 官方依赖项,以避免丢失与 OS 包管理器相关的兼容性和更新。在 Ubuntu 中有很多 python 包,它们有两种不同的版本:一种用于 Python 2.7,一种用于 Python 3.4。首先尝试安装joblib,搜索python 3的python3-joblib包名称或python 2的python-joblib。如果您的Ubuntu版本仍然没有所需的依赖项,您可以使用pip(pip2.7或pip3.4,两者可用作python-pippython3-pip包)。

回答by vishnu viswanath

For me I had the wrong version of joblibinstalled. Reintalling sklearn and joblib solved the issue.

对我来说,我安装了错误版本的joblib。重新安装 sklearn 和 joblib 解决了这个问题。

pip uninstall sklearn
pip uninstall joblib

pip install sklearn
pip install joblib

回答by Julio Cezar Silva

I'm on pip 20.0.2 and python 3.7, and other solutions in here didn't work for me - probably because it all happend on a new condaenv.

我在 pip 20.0.2 和 python 3.7 上,这里的其他解决方案对我不起作用 - 可能是因为这一切都发生在一个新的环境中conda

My env was cloned from the root (conda create -n myenv --clone base) so it might've had influence in joblibnot being there, and pip install joblibhaving no effect. Maybe there's a specific indexing issue in condaenv cloning, but I did manage to solve this by

我的 env 是从根 ( conda create -n myenv --clone base)克隆的,因此它可能会影响joblib不在那里并且pip install joblib没有影响。也许在condaenv 克隆中有一个特定的索引问题,但我确实设法解决了这个问题

conda install joblib