【问题标题】:Real world working solution to anaconda environments and pipanaconda 环境和 pip 的真实世界工作解决方案
【发布时间】:2017-10-15 11:00:37
【问题描述】:

conda 切换到 Python 2.7 环境并使用 pip 安装 mechanize 的实际工作方法是什么?

这是我刚刚测试并获得的全新的全新库存 Anaconda 安装:

C:\Program Files\Anaconda3\Scripts>activate py27

(py27) C:\Program Files\Anaconda3\Scripts>pip install mechanize
Collecting mechanize
  Downloading mechanize-0.3.6.tar.gz (201kB)
    100% |████████████████████████████████| 204kB 1.7MB/s
    Complete output from command python setup.py egg_info:
    mechanize only works on python 2.x

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Temp\pip-build-cmll3
thk\mechanize\

(py27) C:\Program Files\Anaconda3\Scripts>pip install --upgrade setuptools
Collecting setuptools
  Downloading setuptools-36.6.0-py2.py3-none-any.whl (481kB)
    100% |████████████████████████████████| 481kB 428kB/s
Installing collected packages: setuptools
  Found existing installation: setuptools 27.2.0
    Uninstalling setuptools-27.2.0:
      Successfully uninstalled setuptools-27.2.0
Successfully installed setuptools-36.6.0
Traceback (most recent call last):
  File "C:\Program Files\Anaconda3\Scripts\pip-script.py", line 5, in <module>
    sys.exit(pip.main())
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\__init__.py", line 249, in ma
in
    return command.main(cmd_args)
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\basecommand.py", line 252, in
 main
    pip_version_check(session)
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\utils\outdated.py", line 102,
 in pip_version_check
    installed_version = get_installed_version("pip")
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\utils\__init__.py", line 838,
 in get_installed_version
    working_set = pkg_resources.WorkingSet()
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init_
_.py", line 644, in __init__
    self.add_entry(entry)
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init_
_.py", line 700, in add_entry
    for dist in find_distributions(entry, True):
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init_
_.py", line 1949, in find_eggs_in_zip
    if metadata.has_metadata('PKG-INFO'):
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init_
_.py", line 1463, in has_metadata
    return self.egg_info and self._has(self._fn(self.egg_info, name))
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init_
_.py", line 1823, in _has
    return zip_path in self.zipinfo or zip_path in self._index()
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init_
_.py", line 1703, in zipinfo
    return self._zip_manifests.load(self.loader.archive)
  File "C:\Program Files\Anaconda3\lib\site-packages\pip\_vendor\pkg_resources\__init_
_.py", line 1643, in load
    mtime = os.stat(path).st_mtime
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'C:\\Progra
m Files\\Anaconda3\\lib\\site-packages\\setuptools-27.2.0-py3.6.egg'

(py27) C:\Program Files\Anaconda3\Scripts>pip install ez_setup
Collecting ez_setup
  Downloading ez_setup-0.9.tar.gz
Building wheels for collected packages: ez-setup
  Running setup.py bdist_wheel for ez-setup ... done
  Stored in directory: C:\Users\Admin1\AppData\Local\pip\Cache\wheels\53\d6\8b\a2270e6
6cf5f68c038fffcc8b871de0c4326550fb187906bab
Successfully built ez-setup
Installing collected packages: ez-setup
Successfully installed ez-setup-0.9

(py27) C:\Program Files\Anaconda3\Scripts>pip install --upgrade setuptools
Requirement already up-to-date: setuptools in c:\program files\anaconda3\lib\site-pack
ages

(py27) C:\Program Files\Anaconda3\Scripts>pip install --upgrade setuptools --force
Collecting setuptools
  Using cached setuptools-36.6.0-py2.py3-none-any.whl
Installing collected packages: setuptools
  Found existing installation: setuptools 36.6.0
    Uninstalling setuptools-36.6.0:
      Successfully uninstalled setuptools-36.6.0
Successfully installed setuptools-36.6.0

(py27) C:\Program Files\Anaconda3\Scripts>pip install mechanize
Collecting mechanize
  Using cached mechanize-0.3.6.tar.gz
    Complete output from command python setup.py egg_info:
    mechanize only works on python 2.x

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Temp\pip-build-qo4zx
99o\mechanize\

(py27) C:\Program Files\Anaconda3\Scripts>easy_install -U setuptools
Searching for setuptools
Reading https://pypi.python.org/simple/setuptools/
Downloading https://pypi.python.org/packages/45/29/8814bf414e7cd1031e1a3c8a4169218376e
284ea2553cc0822a6ea1c2d78/setuptools-36.6.0.zip#md5=74663b15117d9a2cc5295d76011e6fd1
Best match: setuptools 36.6.0
Processing setuptools-36.6.0.zip
Writing C:\Temp\easy_install-wyi8iiw7\setuptools-36.6.0\setup.cfg
Running setuptools-36.6.0\setup.py -q bdist_egg --dist-dir C:\Temp\easy_install-wyi8ii
w7\setuptools-36.6.0\egg-dist-tmp-eq7ol_dl
warning: no files found matching '*' under directory 'setuptools\_vendor'
Copying setuptools-36.6.0-py3.6.egg to c:\program files\anaconda3\lib\site-packages
Adding setuptools 36.6.0 to easy-install.pth file
Installing easy_install-script.py script to c:\program files\anaconda3\Scripts
Installing easy_install.exe script to c:\program files\anaconda3\Scripts
error: [WinError 5] Access is denied: 'c:\\program files\\anaconda3\\Scripts\\easy_ins
tall.exe'

(py27) C:\Program Files\Anaconda3\Scripts>pip install mechanize
Collecting mechanize
  Using cached mechanize-0.3.6.tar.gz
    Complete output from command python setup.py egg_info:
    mechanize only works on python 2.x

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Temp\pip-build-ui1ll
y8p\mechanize\

(py27) C:\Program Files\Anaconda3\Scripts>pip install --upgrade setuptools --force
(py27) C:\Program Files\Anaconda3\Scripts>
(py27) C:\Program Files\Anaconda3\Scripts>
(py27) C:\Program Files\Anaconda3\Scripts>
(py27) C:\Program Files\Anaconda3\Scripts>python -m pip install --upgrade pip
Requirement already up-to-date: pip in c:\program files\anaconda3\envs\py27\lib\site-p
ackages

(py27) C:\Program Files\Anaconda3\Scripts>pip install mechanize --force
Collecting mechanize
  Using cached mechanize-0.3.6.tar.gz
    Complete output from command python setup.py egg_info:
    mechanize only works on python 2.x

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Temp\pip-build-rsxl3
v5_\mechanize\

【问题讨论】:

  • 问题是您在C:\Anaconda3\Scripts 目录中,所以运行的pip 是Python 3(根环境)的目录。因此,pip 正在尝试为 Python 3 安装,您会收到该错误。您不必在该目录中,并且应尽可能使用conda 安装软件包(下面的答案是 100% 正确)。
  • 另外,如果您正在激活一个名为 py27 的环境,那么这不可能是 Anaconda 的“全新和库存”安装。
  • 它是全新的 - 但由于它是 Anaconda 3x64,我需要创建 2.7 环境。此外,我在哪个目录中执行该命令并不重要,所以不是这样。 Conda 似乎没有正确执行我的意思是简单地将其安装到名称中带有 friggin SPACES 的目录中会炸毁整个事情......而 Visual Studio 2017 我可以在 4 diff python env (3,2.7 - 两者x64、x86 和 2 anaconda env!),但在 conda 中,它似乎并没有按照它所说的那样做。 :(
  • 能不能把where pip不在Scripts目录下的输出贴出来,也把echo %PATH%的输出贴出来?

标签: python anaconda conda


【解决方案1】:

anaconda 的主要优势在于他们花时间编译包(不仅仅是 Python 包)并确保它们彼此兼容,因此所有应该“正常工作”对用户来说。这在 Windows 上特别有用,在 Windows 上编译一些 Python 包可能很困难(而且并非所有东西都在 PyPI 上提供了轮子)。

可以通过conda install &lt;foo&gt; 安装此类软件包。虽然您仍然可以使用pip install &lt;foo&gt;(并且确实需要对无法通过 anaconda 的包管理器提供的任何包这样做),但您应该在包可用的地方使用 conda 安装 - 否则您不会获得 anaconda 想要的好处提供。

所以(根据anaconda's docs for mechanize)你想要:

conda install -c conda-forge mechanize 

(您明确要求不要试图说服您使用不同的方法 - 我认为这意味着您想要使用 anaconda 和 python27,而不是绝对使用 pip。如果 pip 是一个必须为您服务!我相信您所追求的“现实世界解决方案”是在使用 anaconda 时尽可能使用 conda install 而不是 pip install - 请参阅 the answers to this question 以了解 pip 和 conda 之间的差异)

【讨论】:

    猜你喜欢
    • 2011-01-07
    • 1970-01-01
    • 1970-01-01
    • 2021-05-10
    • 1970-01-01
    • 2017-10-10
    • 2019-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多