読者です 読者をやめる 読者になる 読者になる

virtualenvのバージョンが古いとPyPyの環境がうまく作れない。

rubykaigi2013で@matzが言語作ろうよ!的な発表してたので、RPython toolchain使って以前作ったOok!を元にちょっと言語らしくしてみるかと思った。
RPythonのコンパイルはCPythonだと時間かかるので、PyPyでコンパイルすれば時間節約できてー(゚д゚)ウマー。というのを目指す。

で、表題の件で引っかかったので。

  • PyPy2.0.2

失敗した場合は下記の通り。(virtualenvwrapper使ってますが、virtualenvでも同様)

ike-no-MacBook-Air% virtualenv -p /Users/rokujyouhitoma/usr/local/src/pypy-2.0.2/bin/pypy _                                
Running virtualenv with interpreter /Users/rokujyouhitoma/usr/local/src/pypy-2.0.2/bin/pypy
New pypy executable in _/bin/pypy
debug: WARNING: Library path not found, using compiled-in sys.path.
debug: WARNING: 'sys.prefix' will not be set.
debug: WARNING: Make sure the pypy binary is kept inside its tree of files.
debug: WARNING: It is ok to create a symlink to it from somewhere else.
debug: OperationError:
debug:  operror-type: ImportError
debug:  operror-value: No module named os
ERROR: The executable _/bin/pypy is not functioning
ERROR: It thinks sys.prefix is u'/Users/rokujyouhitoma' (should be u'/Users/rokujyouhitoma/_')
ERROR: virtualenv is not compatible with this system or executable

解決策

virtualenvのバージョンを最新にする。

-no-MacBook-Air% sudo easy_install -U virtualenv
Password:
Searching for virtualenv
Reading http://pypi.python.org/simple/virtualenv/
Best match: virtualenv 1.9.1
Downloading http://pypi.python.org/packages/source/v/virtualenv/virtualenv-1.9.1.tar.gz#md5=07e09df0adfca0b2d487e39a4bf2270a
Processing virtualenv-1.9.1.tar.gz
Writing /tmp/easy_install-dDdnB2/virtualenv-1.9.1/setup.cfg
Running virtualenv-1.9.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-dDdnB2/virtualenv-1.9.1/egg-dist-tmp-NJo0g9
warning: no previously-included files matching '*' found under directory 'docs/_templates'
warning: no previously-included files matching '*' found under directory 'docs/_build'
Removing virtualenv 1.8.3 from easy-install.pth file
Adding virtualenv 1.9.1 to easy-install.pth file
Installing virtualenv script to /usr/local/bin
Installing virtualenv-2.7 script to /usr/local/bin

Installed /Library/Python/2.7/site-packages/virtualenv-1.9.1-py2.7.egg
Processing dependencies for virtualenv
Finished processing dependencies for virtualenv

再度トライ

ike-no-MacBook-Air% mkvirtualenv _ --no-site-packages --distribute --python=/Users/rokujyouhitoma/usr/local/src/pypy-2.0.2/bin/pypy
Running virtualenv with interpreter /Users/rokujyouhitoma/usr/local/src/pypy-2.0.2/bin/pypy
Overwriting _/lib-python/2.7/site.py with new content
New pypy executable in _/bin/pypy
Installing distribute...........................................................................................................................................................................................................................done.
Installing pip................done.

うまくいった。