Help us understand the problem. What is going on with this article?

複数のバージョンのPythonをインストールした際のトラブル

背景

Windows 10でPython環境を構築する際に、pyenvのように複数のバージョンを切り替えられないかを検討。

トラブル1 : 同じ系列はダメ

MSIインストーラを利用すると、3.7系を複数インストールできない模様。

Embeddable Edition

StrawberryPerlのPortable editionのようなものがないか探したところ、
embeddable zip fileが提供されているとの情報。

https://qiita.com/mm_sys/items/1fd3a50a930dac3db299

ZIPファイルなので、複数のバージョンを展開するだけでインストール完了。

以下のようなバッチファイルを準備し、PATHを初期化後に利用したいPythonにのみPATHを通す。

python-3.7.4-embed-amd64.bat
@SET PATH=%SYSTEMROOT%\System32
@SET PATH=C:\opt\python-3.7.4-embed-amd64;C:\opt\python-3.7.4-embed-amd64\Scripts;%PATH%

トラブル2 : PYTHONPATHが効かない

環境変数PYTHONHOMEが効かない。原因は不明。
スクリプトの先頭で os.path にパスを追加すれば他のモジュールを読み込めた。

トラブル3:PIPでバイナリパッケージがインストールされない

初めにPython27でsvnをインストールしたらOK。

C:\Python27>python -m pip install svn
Collecting svn
  Downloading https://files.pythonhosted.org/packages/a1/e7/79a64af11e5d2a1e0996e1e2ce781e297ce711d9835fbe37b43dd6134343/svn-0.3.46.tar.gz
Collecting python-dateutil>=2.2 (from svn)
  Downloading https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl (226kB)
    100% |################################| 235kB 2.7MB/s
Collecting nose (from svn)
  Downloading https://files.pythonhosted.org/packages/99/4f/13fb671119e65c4dce97c60e67d3fd9e6f7f809f2b307e2611f4701205cb/nose-1.3.7-py2-none-any.whl (154kB)
    100% |################################| 163kB 1.7MB/s
Collecting six>=1.5 (from python-dateutil>=2.2->svn)
  Downloading https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, nose, svn
  The scripts nosetests-2.7.exe and nosetests.exe are installed in 'C:\Python27\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  Running setup.py install for svn ... done
Successfully installed nose-1.3.7 python-dateutil-2.8.0 six-1.12.0 svn-0.3.46
You are using pip version 18.1, however version 19.2.3 is available.
You should consider upgrading via the 'python -m pip install --upgrade pip' command.

次に、Python37でsvnをインストールしてもOK。

C:\Python37>python -m pip install svn
Collecting svn
  Using cached https://files.pythonhosted.org/packages/a1/e7/79a64af11e5d2a1e0996e1e2ce781e297ce711d9835fbe37b43dd6134343/svn-0.3.46.tar.gz
Collecting python-dateutil>=2.2 (from svn)
  Using cached https://files.pythonhosted.org/packages/41/17/c62faccbfbd163c7f57f3844689e3a78bae1f403648a6afb1d0866d87fbb/python_dateutil-2.8.0-py2.py3-none-any.whl
Collecting nose (from svn)
  Downloading https://files.pythonhosted.org/packages/15/d8/dd071918c040f50fa1cf80da16423af51ff8ce4a0f2399b7bf8de45ac3d9/nose-1.3.7-py3-none-any.whl (154kB)
     |████████████████████████████████| 163kB 2.2MB/s
Collecting six>=1.5 (from python-dateutil>=2.2->svn)
  Using cached https://files.pythonhosted.org/packages/73/fb/00a976f728d0d1fecfe898238ce23f502a721c0ac0ecfedb80e0d88c64e9/six-1.12.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, nose, svn
  WARNING: The scripts nosetests-3.4.exe and nosetests.exe are installed in 'C:\Python37\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  Running setup.py install for svn ... done
Successfully installed nose-1.3.7 python-dateutil-2.8.0 six-1.12.0 svn-0.3.46

最後に python-3.7.4-embed-amd64でsvnをインストールしようとするとNG。

c:\opt>python -m pip install svn
Collecting svn
  Using cached https://files.pythonhosted.org/packages/a1/e7/79a64af11e5d2a1e0996e1e2ce781e297ce711d9835fbe37b43dd6134343/svn-0.3.46.tar.gz
    ERROR: Command errored out with exit status 1:
     command: 'C:\opt\python-3.7.4-embed-amd64\python.exe' -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\kojiro\\AppData\\Local\\Temp\\pip-install-o1yky_u3\\svn\\setup.py'"'"'; __file__='"'"'C:\\Users\\kojiro\\AppData\\Local\\Temp\\pip-install-o1yky_u3\\svn\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base pip-egg-info
         cwd: C:\Users\kojiro\AppData\Local\Temp\pip-install-o1yky_u3\svn\
    Complete output (5 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\kojiro\AppData\Local\Temp\pip-install-o1yky_u3\svn\setup.py", line 4, in <module>
        import svn
    ModuleNotFoundError: No module named 'svn'
    ----------------------------------------
ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.

以下のキャッシュフォルダを削除しても変わらず。

C:\Users\<USERNAME>\AppData\Local\pip\cache

ここで、他のPCの環境を調査したところ、python-3.7.4-embed-amd64 のみをインストールした環境では whlファイルをインストールしていることを確認。

そこで、PIPのオプションを調査し、--only-binary というオプションがあることを確認。このオプションを指定して再度インストールを試みたところ、無事にパッケージをインストールできた。

c:\opt>python -m pip install --only-binary :all: svn
Collecting svn
  Using cached https://files.pythonhosted.org/packages/f5/d5/07b3bcc6820320754d607f6a49d92e16bc4f8e6f33d6c55304e366f7dcfd/svn-0.3.44-py2.py3-none-any.whl
Requirement already satisfied: python-dateutil>=2.2 in .\python-3.7.4-embed-amd64\lib\site-packages (from svn) (2.8.0)
Requirement already satisfied: nose in .\python-3.7.4-embed-amd64\lib\site-packages (from svn) (1.3.7)
Requirement already satisfied: six>=1.5 in .\python-3.7.4-embed-amd64\lib\site-packages (from python-dateutil>=2.2->svn) (1.12.0)
Installing collected packages: svn
Successfully installed svn-0.3.44

教訓

embeddable zip fileを利用すると他のPythonと競合することがあるので注意すること。

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away