Virtualenv-DeprecationWarning:不建议使用imp模块,而建议使用importlib

时间:2018-09-22 00:15:49

标签: python-3.x virtualenv homebrew pipenv

我正在使用pipenv安装beautifulsoup,由于某种原因,我收到了弃用警告。 (就上下文而言,我使用brew安装python,并使用pip3安装pipenv):

Creating a virtualenv for this project...
Pipfile: /Users/kylemart/Desktop/test/Pipfile
Using /usr/local/bin/python3.7m (3.7.0) to create virtualenv...
⠋Running virtualenv with interpreter /usr/local/bin/python3.7m
Using base prefix '/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7'
/usr/local/lib/python3.7/site-packages/virtualenv.py:1041: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
  import imp
New python executable in /Users/kylemart/.local/share/virtualenvs/test-F6PO10ji/bin/python3.7
Also creating executable in /Users/kylemart/.local/share/virtualenvs/test-F6PO10ji/bin/python
Installing setuptools, pip, wheel...done.
Setting project for test-F6PO10ji to /Users/kylemart/Desktop/test

Virtualenv location: /Users/kylemart/.local/share/virtualenvs/test-F6PO10ji
Installing beautifulsoup4...
Collecting beautifulsoup4
  Using cached https://files.pythonhosted.org/packages/21/0a/47fdf541c97fd9b6a610cb5fd518175308a7cc60569962e776ac52420387/beautifulsoup4-4.6.3-py3-none-any.whl
Installing collected packages: beautifulsoup4
Successfully installed beautifulsoup4-4.6.3

Adding beautifulsoup4 to Pipfile's [packages]...
Installing dependencies from Pipfile.lock (4df8f1)...
     ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 1/1 — 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.

如何解决此问题?

2 个答案:

答案 0 :(得分:0)

我也面临着同样的问题,但是我的情况是与sklearn Library有关,为了解决警告,这是我所做的(您也可以这样做):

  1. 使用名为cloudpickle.py的编辑权限打开文件,该文件位于此位置\sklearn\externals\joblib\externals\cloudpickle\cloudpickle.py
  2. 替换import impfrom imp import find_moduleimport importlib位于文件顶部。
  3. 找到名为find_module的函数并替换该行 file, path, description = find_module(path)file, path, description = importlib.utils.find_spec(path)

因此,总而言之,您必须在引发错误的文件中用imp module替换importlib的提及。对于您而言,该文件位于/usr/local/lib/python3.7/site-packages/virtualenv.py

您可以参考https://docs.python.org/3/library/imp.htmlhttps://docs.python.org/3/library/importlib.html#module-importlib中有关该模块的更多信息。

答案 1 :(得分:0)

我也面临着同样的问题。在我的Linux机器上,我只是删除已安装的软件包 numpy pandas 并重新安装。终于我的问题解决了。

尝试一下。

pip uninstall pandas
pip uninstall numpy
pip install pandas
pip install numpy