码迷,mamicode.com
首页 > 其他好文 > 详细

PyPy与VirtualEnv的安装问题

时间:2015-01-07 23:25:59      阅读:743      评论:0      收藏:0      [点我收藏+]

标签:

PyPy与VirtualEnv的安装问题


说明:本博客由bitpeach原创撰写,请勿商用。转载免费,请注明出处,谢谢。

(零)背景

  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来指定一个虚拟环境。因此,产生了一些问题。然而问题是促进进步的根源,问题是改变现状的动力,问题带来了许多意想不到的事情。

(一)需求

  这些与我研究相关的东西制作起来很耗时耗力,我一天只能制作百分之几的工作量,原因在于我的研究比较繁琐,需要不断统计数据, 不断验证数据,不断评价数据。使用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为默认解释器,然而在输入完毕后报错。

     主要问题整理为:

(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吧。

  

   

 

PyPy与VirtualEnv的安装问题

标签:

原文地址:http://www.cnblogs.com/bitpeach/p/4209530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!