'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.
Solution 1:[1]
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
- this include "don't install anything into my unstable and oversized Windows"
- but doesn't necessarily "must use the Official Embedded Distribution"
- something portable and trusted is enough, yes Portable Python
- but the main page says "Portable Python is not being developed anymore", and provide some choice
- after some reading, I figured out, what I want is WinPython, the version with a Zero
- 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.
Solution 2:[2]
The embedded distribution is meant to be lightweight. To install a virtual environment, follow these steps.
https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
Once these steps are done, proceed with the recommended approach and create a virtual environment using the command below. The --system-site-packages is typically used to bring a non embedded distribution packages already in the python install into the virtual environment, but since this is embedded, you can omit. But it won't hurt to have it.
python -m venv --system-site-packages C:\Python\python-3.7.9-embed-amd64\py37venv
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 |