Make it possible with Python.

最近Pythonから離れ気味、その他物作りに寄り気味です。

Python仮想環境virtualenvをPyscripterに適用する方法

Webサービスを作るためには、依存関係によるトラブルを防ぐために各アプリを仮想環境で作る必要があるらしい。

ということで、virtualenvを pipからインストールして、仮想環境を作ってみました。

が、ここから先が地獄でした。

仮想環境をactivateしても、SpyderやpyscripterなどのIDEで、それが適用されない。。

そして、この件に関する情報が日本語サイトに殆どない・・・・・・。

Pythonに日本語情報が少ないというのはよくきいていましたが、こういう、ちょっと深いところをやろうとすると、とたんに情報が少なくなるということなんですね。

結局、Spyderに適用することはあきらめ、Pyscripterについては、 以下のバッチファイルによりvirtualenvのactivateとPyscripterを行うことで、なんとか実現できました。

CALL W:\bin\v_env\Scripts\activate.bat
SET PYTHONHOME=%VIRTUAL_ENV%
"W:\Application_settings\PyScripter\PyScripter.exe" --PYTHON27 --PYTHONDLLPATH "C:\Windows\SysWOW64" %1 %2 %3 %4 %5

仕組みはわかっていないので、どなたか教えていただけると嬉しいです。

参考URL: FAQ - pyscripter - An open-source Python Integrated Development Environment (IDE) - Google Project Hosting

念のためコメント欄より転載。

How do I use PyScripter with virtualenv? There's a problem if you use PyScripter with the remote python engine in a virutalenv environment. On Microsoft Windows, if ENV is your virtual python environment (created with 'python virtualenv.py ENV'), then after switching to this environment, the python.exe executable is located in C:\Python27\ENV\Scripts. (Or whatever your Python version and installation directory is) However, PyScripter expects it to be in C:\Python27\ENV. You can use this workaround: Create a symbolic link from C:\Python27\ENV\python.exe to C:\Python27\ENV\Scripts\python.exe . On Windows Vista or 7, you may use the mklink command to do this:

mklink C:\Python27\ENV\python.exe C:\Python27\ENV\Scripts\python.exe 

(you'll need administrator privilleges to do this). Start PyScripter via a batch file with the following commands:

CALL C:\Python27\ENV\Scripts\activate.bat SET PYTHONHOME=%VIRTUAL_ENV% START project.psproj

The first line activates the virtual environment ENV. The second line sets the PYTHONHOME environment variable to the one defined by virtualenv, i.e. 'C:\Python27\ENV'. This is that Python finds all libraries specific to that environment. The last line starts PyScripter via a project file. You might as well call PyScripter.exe directly. Versions tested: Python 2.7.3 PyScripter 2.5.3.0 x86 virtualenv 1.8.2 on Windows 7 (32 bit)