PyPy與VirtualEnv的安裝問題html
說明:本博客由bitpeach原創撰寫,請勿商用。轉載免費,請註明出處,謝謝。python
(零)背景linux
VirtualEnv工具的詳細內容是什麼,請自行百度。這裏大概簡介,主要是實現不一樣版本或不一樣環境的Python執行相互不產生干擾。有點像python界的虛擬機,能夠這麼粗淺的理解。例如,有時須要python2.x,有時也須要python3.x。同時在一臺主機上安裝兩個不一樣版本。首先這兩個不一樣版本的python須要安裝第三方庫,可能會產生干擾。其次,這兩個版本python啓動或尋找import庫時,有可能由於兩個版本python的路徑或系統環境變量設置不當,致使沒法運行成功。因此,建議使用virtualenv,這樣不一樣的虛擬世界不會產生干擾。PyPy則是Python的另外一版本,實際上它不屬於任何版本。它至關於python的基因變異者,實現了python基因的異化,產生了python的「變種人」世界。儘管python已很是具備效率,Cython的設計也爲此作出了改變,可是橫空出世的pypy在根本上最爲很是,有力地改變了python的效率局面,由於PyPy某種程度上就是python自己。我須要安裝PyPy,可是擔憂與python2.7產生衝突,因而使用virtualenv來指定一個虛擬環境。所以,產生了一些問題。然而問題是促進進步的根源,問題是改變現狀的動力,問題帶來了許多意想不到的事情。windows
(一)需求python3.x
這些與我研究相關的東西製做起來很耗時耗力,我一天只能製做百分之幾的工做量,緣由在於個人研究比較繁瑣,須要不斷統計數據, 不斷驗證數據,不斷評價數據。使用python是首選,便於調試編譯,便於變化和改裝。然而我須要使用pypy加速個人程序,首先由於我寫程序寫得太爛,不太會優化python代碼。第二,python多線程問題未能解決。所以我曾撰寫了python多線程問題的簡單討論,有興趣者能夠參看博文《Python多線程問題的資料查找與彙總by tsy 》。因爲GIL問題困擾了python,我在實際操做的時候發現有時候python多線程執行還不如單線程。關鍵問題仍是未能解鎖GIL,有網友能夠作到程序上解鎖,可是我感到有些吃力和困難。所以我決定使用Cython或PyPy,Cython可能會在寒假期間寫一篇專文。微信
使用virtualenv爲pypy指定的方法,最初是學習the5fire網友,其博文《建立基於pypy的virtualenv虛擬環境》很是有參考價值。thefivefire主要作的嘗試是在linux上,故與我有一些不一樣。個人環境是windows8,python2.7.3,virtualenv1.11.x-win32.exe。與之幾封郵件交互後,thefivefire說的很對,pypy部署在windows上較少,pypy的第三方庫支持較少。因而我直接找到pypy主頁[http://pypy.org/],找到主站管理團隊的聯繫方式,用郵件交流了。該維護團隊人數仍是很是多的,維護人員名字能夠參看網址[https://bitbucket.org/pypy/pypy/src/tip/LICENSE]。多線程
(二)郵件交流併發
第一封郵件提出問題,windows下virtualenv爲pypy指定默認解釋器(該操做請自行百度),須要使用指令<virtualenv -p>,不然默認指定爲系統版本python。顯然若是使用pypy加速,固然不能選擇系統版本。所以須要使用virtualenv指令,指定pypy爲默認解釋器,然而在輸入完畢後報錯。app
主要問題整理爲:dom
(1)I want to instal Pypy but do not confuse the the 3rd packages or libraries with Python2.7 already in my operate system Windows 7/8 (32bit). Then I choose to follow the tutorial settings to install VirtualEnv just like "Installing using virtualenv".
(2)After I install VirtualEnv successfully, I need to arrange a new space for Pypy so that I download the Pypy available to Windows as Python2.7 compatible PyPy 2.4.0 - Windows binary (32bit) shown.(3)Then I extract the pypy-2.4.0-win32.zip file to normal foleder and use VirutalEnv commands like ">virtualenv.exe -p \pathto\pypy.exe". This command "-p $PATH" means I need to choose Pypy as a default Python interpreter,otherwise it will choose Python27 already installed in my Windows system. However the command comes a error and fail to build a virtual environment for pypy.From now on, I truly realized that the specific parameters in the command in windows and Unix/Linux is different. Although I notice that your tutorial shows that $ virtualenv -p /opt/pypy-c-jit-41718-3fb486695f20-linux/bin/pypy my-pypy-env with a difference between Windows7/8 and Unix/Linux, I still can not solve the problem in Windows 7/8 and do not know how to build a virtual environment with appointing Pypy to a default interpreting python environment in Windows 7/8.
團隊成員回信整理以下:
The latest released virtualenv is version 1.11.6 which does not support pypy 2.4.0 and earlier on windows. A fix was merged into virtualenv after this version (released 17 May 2014) so any newer release will be fixed. In the mean time you can:
1. run "virtualenv -p path\to\pypy.exe new_path" and it will fail
2. copy by hand the directories lib_pypy and lib-python from path\to to new_path
3. rerun virtualenv, it should complete cleanly after installing setuptools and pip
回信明確指出了目前尚未virtualenv能夠作到支持最新的pypy,不過他提供了一種方式做爲嘗試。我按照其操做,仍是失敗。我後來思考認爲,這樣的操做是解決這個問題的最好方式,不成功的緣由我認爲只能歸結爲virtualenv工具的功能還不夠強大。所以我查詢了virtualenv的相關說明。virtualenv在本博文撰寫時目前已更新到12.0.5(2015-01-03),在它的版本更新歷史中大體經歷了0.8.x至1.11.x的幾十次更新。當時報錯的時候,是2014年12月實驗的事情。當時我使用1.11.x版本,下文的1.5版本寫到開始支持pypy,可是我查詢了材料,應該指的是爲pypy所用。1.7.2開始能夠在windows系統上操做使用virtualenv,來用於pypy功能。1.10版本能夠指定默認解釋器。
1.5 ~~~ * Add support for PyPy.1.10 (2013-07-23) ~~~~~~~~~~~~~~~~~ * Added support for PyPy3k * Added the option to use a version number with the ``-p`` option to get the system copy of that Python version (Windows only)
根據上述版本說明的引證,說明virtualenv支持pypy,和指定pypy爲默認解釋器,仍是兩碼事的。1.10版本只是說能夠指定默認解釋器,但沒說能夠指定pypy.exe。因此我誤覺得1.11.x版本也能夠作到。因而我當時只能死馬當活馬醫,因此按照上面的郵件回覆,將pypy的lib庫複製在虛擬環境下,可是啓動失敗了,當時12月中旬,我將錯誤總結併發出第二封郵件以下。(請注意下面使用的方法是有問題,因此我才把錯誤彙總,再次尋求幫助。)
With your help, I have some new questions as follows.
(1) I check the VirtualEnv version list and the 1.11.6 is the latest by this URL. There is no newer version than that. It means that 1.11.6 version is the newest and no versions can support pypy-2.4.0.(2) Then I keep the complete file of Pypy-2.4.0 as an old path and build a new file to copy the directories lib_pypy and lib-python into the new file.(3) And I use the command "virtualenv -p \path\to\oldfile\pypy.exe \path\to\newfile". As the pictures below, please allow me to explain them.[3-1] I already install python2.7 and virtualenv 1.11.6.[3-2] I put a complete pypy-2.4.0 programs in file "e:\Python27\Scripts\pypy-2.4.0-win32" as an old path. The Picture below presents this.(3-2 Picture)[3-3] I build a new file named "VirtualenvPypy" and copy the directories lib_pypy & lib-python from file "pypy-2.4.0-win32" to new file "VirtualenvPypy". The Picture below presents this.(3-3 Picture)[3-4] Finally, I use the command as below. The two Pictures below present this. In (3-4 Picture B), the red one is old path and the blue one new path. If my command is wrong, you can help me to revise it.(3-4 Picture A)(3-4 Picture B)(4) The command is failed. And I guess the intention to appointing pypy.exe as a default interpret may be not available to the Windows 7/8 versions and Pypy-2.4.0. I still worry a truth that a lot of materials in foreign or domestic forums are about pypy-2.4.0 with VirtualEnv in Linux such as CentOs. I really doubt my idea of installing pypy-2.4.0 in virtualenv with Windows 7/8 is correct. All pictures are uploaded as attachments.
綜上版本1.11.x不夠用,因此這封郵件一直沒有獲得回覆。直到。。。今天晚上Armin Rigo答覆並提醒最新virtualenv已經發布。
I see that the current virtualenv version is now 12.0.5 (https://pypi.python.org/pypi/virtualenv/#downloads). I assume that this means that the fixes Matti talks about are now officially part of it. Can you try again with this version 12.0.5?
一查看確實如此,發佈了新的版本virtualenv,而後再試試,發現可使用,成功設置了虛擬環境,並制定了pypy爲默認解釋器,下圖就是例證,相關virtualenv的指令使用,能夠搜索相關博客或百度文庫,或者這裏能夠提供virtualenv指令文檔的下載,請點擊我。值得讚許的是virtualenv仍是很是快的發佈了新工具,而且此次版本號從1.11.6直接邁到12.0,而後又到了如今(2015-1-7)的12.0.5。看來版本內容有些重要的改變。值得進一步探索。
(三)總結思考
總結經驗:若是在windows下使用virtualenv指定pypy2.4.0爲默認器,須要virtualenv版本在12.0.5。是否是12.0.x以上須要自行驗證,由於我只試驗了12.0.5版本。上面文章其實就是爲了驗證這麼一句話:整個過程說明了最新的pypy2.4.0與1.11.x版本的virtualenv在windows下是不搭界的,最起碼須要使用12.0.5版本。
因此又驗證了一句話,科學技術的精髓在於不斷的探索,驗證,即折騰。PyPy加速與Cython相媲美,整體來看仍是很是不錯的。目前pypy確實還不太成熟,許多第三方庫未能獲得支持,因此該主頁發起捐助活動,捐助項目有科學計算包,有支持python3.x的pypy版本,還有STM(這個東西就是移除GIL,或許是實現單核加速,多線程真正實現的關鍵成品)。根據資金項目,整體來看,編寫人數較多,開支較大,時間若規劃的當,猜想2015年末,各基礎科學計算包,如numpy,scipy等,支持pypy的版本會相繼出爐。借用the5fire網友的話,人生短暫,仍是用python吧。
<<<<<<<<< 寫在頁面最底的小額打賞 >>>>>>>>>
若是讀者親願意的話,能夠小額打賞我,感謝您的打賞。您的打賞是個人動力,很是感激。
必讀:如您願意打賞,打賞方式任選其一,本頁面右側的公告欄有支付寶方式打賞,微信方式打賞。
避免因打賞產生法律問題,兩種打賞方式的任一打賞金額上限均爲5元,謝謝您的支持。
若有問題,請24小時內通知本人郵件。