Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VirtualEnv and python-embed

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.

like image 331
Tenescu Andrei Avatar asked Dec 11 '17 13:12

Tenescu Andrei


People also ask

Is virtualenv deprecated?

The ActiveState Platform is a modern solution to dependency management. Virtualenv has been deprecated in Python 3.8.

Is virtualenv better than VENV?

These are almost completely interchangeable, the difference being that virtualenv supports older python versions and has a few more minor unique features, while venv is in the standard library.

How does Python connect to virtual environment?

To use the virtual environment you created to run Python scripts, simply invoke Python from the command line in the context where you activated it. For instance, to run a script, just run python myscript.py .

Does virtualenv install pip?

Activating a virtual environmentAs long as your virtual environment is activated pip will install packages into that specific environment and you'll be able to import and use packages in your Python application.


1 Answers

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

Update on 17 December 2021

The download page has been moved to https://winpython.github.io/ , for my purpose, I will download Winpython64-3.10.0.1dot.exe for now. Please don't forget to verify the checksum for the executable package.

End of the update on 17 December 2021

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.

like image 148
Windsting Avatar answered Sep 22 '22 08:09

Windsting