VirtualEnv和python-embed [英] VirtualEnv and python-embed

查看:197
本文介绍了VirtualEnv和python-embed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一台Windows计算机,该计算机使用Python 2运行许多应用程序。我想添加一个我使用Python 3编写的新程序。为确保我不会搞砸任何东西,我想在其中使用Virtualenv嵌入式Python 3( Python 3嵌入amd64 )。



因此,我提取了嵌入式python 3,并尝试在启用--python选项的情况下运行virualenv。



我尝试运行virtualenv

  python -m virtualenv-蟒蛇E:\Projects\python3-embed\python.exe E:\Projects\Virtual\ 

我得到了这个错误:

 运行带有解释程序E的virtualenv:\项目\python3-embed\ \python.exe 
使用基本前缀'E:\\Projects\\python3-embed'
追溯(最近一次调用):
文件 C:\Python27 < module>中的 libsite-packagesvirtualenv.py行2328。
main()
文件 C:\Python27\lib\site-packages\virtualenv.py,行713,在主
中symlink = options.symlink)
文件 C:$ Python27 $ lib\site-packages\virtualenv.py,行925,在create_environment中
site_packages = site_packages,clear = clear,symlink = symlink))
在install_python
writefile(site_filename_dst,SITE_PY)中的文件 C:\Python27\lib\site-packages\virtualenv.py,行1147
文件 C:\Python27\ lib\site-packages\virtualenv.py,第362行,在writefile
中,open(dest,'wb')为f:
FileNotFoundError:[Errno 2]没有这样的文件或目录: 'E:\\Projects\\Virtual\\python36.zip\\site.py'

我不确定如何解决此错误。 python36.zip中有一个site.pyd文件,但似乎virtualenv无法使用它。

解决方案

对不起



知道,这不是您要问的答案,但是我努力尝试 (我们) 方式,最后得到了这个解决方案。






TL; DR



使用 来自 WinPython

$ b的后缀为 Zero 的便携式安装程序
$ b

  • WinPython64-3.7.0.2Zero.exe(64位版本,您想要这个

  • WinPython32-3.7.0.2Zero.exe(32位版本)






em>太长版本



我尝试过的




  • 是,我下载了 python-3.7.0-embed-amd6来自此页面
  • 中的4.zip b $ b
  • 是的,我根据此页面

  • 是的,它用作python解释器

      D:\temp\test> python 
    Python 3.7.0(v3.7.0:1bf9cc5093,Jun 27 2018,04:59:51) [win32
    >>上的[MSC v.1914 64位(AMD64)]


  • 是的,我安装了软件包 virtualenv

      D:\temp\test> virtualenv --version 
    16.0.0


  • 然后,繁荣(在您要求的地方)

      D:\temp\test> virtualenv ENV 
    使用基本前缀'd:\\portable\\python-3.7.0-embed-amd64 '
    追溯(最近一次通话最后一次):
    文件 runpy.py,第193行,在_run_module_as_main中
    文件 runpy.py,第85行,在_run_code
    文件中 D:module便携式\python-3.7.0-embed-amd64\Scripts\virtualenv.exe\__main __。py,第9行,< module>
    在主
    symlink = options中的行712中,文件 D:\portable\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py。 symlink)
    文件 D:便携式python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py,第927行,位于create_environment
    site_packages = site_packages,clear = clear,symlink = symlink))
    文件 D:\便携式\python-3.7.0-embed-amd64\lib\site\packages\virtualenv.py,行1149 ,在install_python
    writefile(site_filename_dst,SITE_PY)中
    文件 D:\便携式\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py中,第363行,在writefile
    中,open(dest,'wb')为f:
    FileNotFoundError:[Errno 2]没有这样的文件或目录:'D:\\temp\\test \\ENV\\python37.zip\\site.py'

    似乎搜索了 virtualenv 的问题后,得到了一个未解决的问题,我不喜欢这么长的解决方案。



    这是virtualenv的


  • 然后,我尝试了 venv

      D:\temp\test> python -m venv venv 
    D:\ Portable\python-3.7.0-embed-amd64\python.exe:没有名为venv



    是的,内置模块 丢失了,并且嵌入式发行版文档甚至都没有提及,只是不包括 Tcl / tk(...),pip和Python文档。 / p>

    这是venv的结尾




好吧,从我的原点重新开始



选择嵌入式分布的目的是(就像 SOMEBODY ):


确保我不会弄乱任何东西





  1. 此包含ude 不要在我的不稳定和超大尺寸的Windows中安装任何东西

  2. ,但不一定是 必须使用 官方嵌入式发行版

  3. 只要便携式且受信任,就可以了,是的 便携式Python

  4. 但主页上显示便携式Python已不再开发,并提供一些选择

  5. 经过一番阅读,我发现我想要的是 WinPython ,带有

  6. ta-da ... 就是这样
  7. >



有关嵌入式发行版的信息(来自官方文件




嵌入式分发是ZIP文件,保持最小的Python环境。 旨在作为另一个应用程序的一部分,而不是最终用户直接访问。



I have a Windows machine running many apps using Python 2. I want to add a new program I wrote using Python 3. To make sure I don't screw anything up, I wanted to use a Virtualenv with Python 3 embedded (Python 3 embed amd64).

So I extracted the embedded python 3 and tried running virualenv with the --python option enabled.

I tried running the virtualenv

    python -m virtualenv --python E:\Projects\python3-embed\python.exe E:\Projects\Virtual\

And I got this error:

Running virtualenv with interpreter E:\Projects\python3-embed\python.exe
Using base prefix 'E:\\Projects\\python3-embed'
Traceback (most recent call last):
  File "C:\Python27\lib\site-packages\virtualenv.py", line 2328, in <module>
    main()
  File "C:\Python27\lib\site-packages\virtualenv.py", line 713, in main
    symlink=options.symlink)
  File "C:\Python27\lib\site-packages\virtualenv.py", line 925, in create_environment
    site_packages=site_packages, clear=clear, symlink=symlink))
  File "C:\Python27\lib\site-packages\virtualenv.py", line 1147, in install_python
    writefile(site_filename_dst, SITE_PY)
  File "C:\Python27\lib\site-packages\virtualenv.py", line 362, in writefile
    with open(dest, 'wb') as f:
FileNotFoundError: [Errno 2] No such file or directory: 'E:\\Projects\\Virtual\\python36.zip\\site.py'

I am not entirely sure how can I fix this error. There is a site.pyd file in python36.zip but it seems that virtualenv can't use it.

解决方案

Sorry in advance

I knew this is not the answer you meant to ask for, but I tried hard that (our) way, and got this solution at last.


TL;DR

Use the portable installer with postfix "Zero" from WinPython

  • WinPython64-3.7.0.2Zero.exe(64 bit version, YOU want this)
  • WinPython32-3.7.0.2Zero.exe(32 bit version)

The Too Long version

What I tried

  • Yes, I downloaded the python-3.7.0-embed-amd64.zip from this page
  • Yes, I set it up according to instructions in this page
  • Yes, it worked as a python interpreter

    D:\temp\test>python
    Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:59:51) [MSC v.1914 64 bit (AMD64)] on win32
    >>>
    

  • Yes, I installed the package virtualenv

    D:\temp\test>virtualenv --version
    16.0.0
    

  • Then, boom (where you asked)

    D:\temp\test>virtualenv ENV
    Using base prefix 'd:\\portable\\python-3.7.0-embed-amd64'
    Traceback (most recent call last):
    File "runpy.py", line 193, in _run_module_as_main
    File "runpy.py", line 85, in _run_code
    File "D:\portable\python-3.7.0-embed-amd64\Scripts\virtualenv.exe\__main__.py", line 9, in <module>
    File "D:\portable\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py", line 712, in main
        symlink=options.symlink)
    File "D:\portable\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py", line 927, in create_environment
        site_packages=site_packages, clear=clear, symlink=symlink))
    File "D:\portable\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py", line 1149, in install_python
        writefile(site_filename_dst, SITE_PY)
    File "D:\portable\python-3.7.0-embed-amd64\lib\site-packages\virtualenv.py", line 363, in writefile
        with open(dest, 'wb') as f:
    FileNotFoundError: [Errno 2] No such file or directory: 'D:\\temp\\test\\ENV\\python37.zip\\site.py'
    

    Seems a problem with virtualenv, searched, got an open issue, and I don't like that long solution.

    This is the end of virtualenv.

  • Then, I tried venv:

    D:\temp\test>python -m venv venv
    D:\portable\python-3.7.0-embed-amd64\python.exe: No module named venv
    

    Yes, the "built-in module" was lost, and the document for Embedded Distribution doesn't even mention it, just something about Tcl/tk (...), pip and the Python documentation are not included.

    This is the end of venv.

Well, start again from my original point

The purpose to choose Embedded Distribution is (just like SOMEBODY):

To make sure I don't screw anything up

  1. this include "don't install anything into my unstable and oversized Windows"
  2. but doesn't necessarily "must use the Official Embedded Distribution"
  3. something portable and trusted is enough, yes Portable Python
  4. but the main page says "Portable Python is not being developed anymore", and provide some choice
  5. after some reading, I figured out, what I want is WinPython, the version with a Zero
  6. ta-da ... That's it.

Something about Embedded Distribution (from official document)

The embedded distribution is a ZIP file containing a minimal Python environment. It is intended for acting as part of another application, rather than being directly accessed by end-users.

这篇关于VirtualEnv和python-embed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆