-1

What is the real world proven working method to conda switch to a Python 2.7 environment and install mechanize using pip?

Here's a new brand new stock Anaconda install which I just tested and get:

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\
darthbith
  • 18,484
  • 9
  • 60
  • 76
Collin Chaffin
  • 872
  • 9
  • 15
  • The problem is that you're in the `C:\Anaconda3\Scripts` directory, so the `pip` that's run is the one for Python 3 (the root environment). Thus, `pip` is attempting to install for Python 3, and you get that error. You need to not be in that directory, and you should use `conda` to install packages whenever possible (the answer below is 100% correct). – darthbith Oct 15 '17 at 16:06
  • Also, if you're activating an environment called `py27`, there's no way this is a "brand new and stock" installation of Anaconda. – darthbith Oct 15 '17 at 16:06
  • It is brand new - but as it was the Anaconda 3x64 I needed to create the 2.7 env. Also, it doesn't matter what directory I'm in for that command, so that is not it. Conda simply does NOT seem to do it properly I mean simply installing it into a directory with friggin SPACES in the name blows the whole thing up....whereas Visual Studio 2017 I can switch between 4 diff python env (3,2.7 - both x64,x86, AND 2 anaconda env!), yet within conda it doesn't seem to do what it says it should be able to. :( – Collin Chaffin Oct 18 '17 at 04:04
  • Can you post the output of `where pip` when you're not in the Scripts directory, and also the output of `echo %PATH%`? – darthbith Oct 18 '17 at 13:58

1 Answers1

3

The main advantage of anaconda is that they've taken the time to compile packages (not just Python ones) and ensure they're compatible with each other, so that everything should "just work' for the user. This is especially useful on Windows, where compiling some Python packages may be difficult (and not everything has a wheel available on PyPI).

Such packages are available to install via conda install <foo>. Whilst you can still use pip install <foo> (and indeed will need to do so for any packages not available through anaconda's package manager), you should use the conda install where packages are available - otherwise you're not getting the benefit that anaconda intends to provide.

So (as per anaconda's docs for mechanize) you want:

conda install -c conda-forge mechanize 

(You explicitly requested no attempts to convince you to use a different approach - I'm taking that to mean that you want to use anaconda and python27, rather than to definitely use pip. Obviously this is no help if pip is a must for you! I believe the "real world solution" that you're after is to use conda install rather than pip install wherever possible when using anaconda - see the answers to this question for an explanation of the differences between pip and conda)

emmagordon
  • 1,222
  • 8
  • 17