Reputation: 661
I installed the latest version of Python 3.8.2 on a Windows 10 machine. I previously had Python 3.7, which I uninstalled and confirmed in the System PATH it was no longer referenced.
After installing the latest version, I run through CMD as Admin:
py -m venv env
and I get this error:
Error: [WinError 2] The system cannot find the file specified: 'C:\Users\test_user\Documents\app_test\env'
I know the Python Path is in the System Path environmental settings, but not specifically for the user (don't know if that makes a difference?).
I have also tried to uninstall virtualenv using powershell and reinstaling, but have the same result.
Any ideas on where else to look to solve this?
Upvotes: 34
Views: 88426
Reputation: 30248
This is often due to the path variable, I have found that winget uninstall
doesn't remove python path entries, and this was all I needed to fix to resolve the error.
Fatal error in launcher: Unable to create process using '"C:\Python311\python.exe" "C:\Python311\Scripts\pip.exe" ': The system cannot find the file specified.
From start menu, I enter env
:
Select "Edit the system environment variables"
Click Environment Variables
and check path
in System variables, if you have any path entries with Python
after uninstalling Python, edit the path and remove them. (Take care to edit the path properly.)
Then reinstall via winget:
# For example re-install Python 3.11, (use the version you require.)
winget install python3.11
Do not edit the path if you are not sure what you're doing!
Upvotes: 0
Reputation: 1
I found out that, simply using a shorter path fixed this error. Try creating your virual environment in the C: directory.Hope this helps.
Upvotes: 0
Reputation: 31
I had the same problem and I upgraded the pip inside of venv and that worked out . my problem was that I could not install anything inside of venv like django but when I upgraded the pip everything went well. the command you have to use is:
> python -m pip install --upgrade pip
$ pip install --upgrade pip
$ pip install --upgrade pip
Upvotes: 1
Reputation: 3091
If you don't like the approach "disable your Windows 10 "Ranswomare Security Protection",
Run the setup comment again, hope it'll work peacefully.
Upvotes: 8
Reputation: 3634
You probably encounter this error because you have two or more versions of Python on your machine. When installing the second version, you:
PYTHON37_HOME -> C:/Users/..Python/Python37
)Path
.python.exe
to python37.exe
Now by opening the file C:\Users\....\Python\Python37\Lib\venv\__init__.py
you can see that by executing the setup_python()
function, python.exe
cannot be found anymore in the suffixes = ['python.exe', ...]
because we renamed it.
So you also have to rename suffixes = ['python.exe', ...]
to suffixes = ['python37.exe', ...]
.
Execute again python37 -m venv venv
and it should work
Upvotes: 12
Reputation: 938
I got the WinError 2 because I have multiple python3 installed with different version and I was renamed the python.exe to other name. I have tried all solution offered in this post including turning down the firewall. Unluckily, I still got the winerror. So, I have to edit venv init in [python path]/Lib/venv/init.py. Find python_exe variable and change its value from python.exe to your new python executable name (in my case it's python39.exe). Also, find variable named suffixes and change the python.exe in suffix list to your python executable name. Finally, test it to make an env and activate it. The WinError Issues solved.
Upvotes: 0
Reputation: 47
I have faced the same issue. And solve it using a simple trick. Some packages need folder permission to get installed, todo so uses cmd with administrator access and then install whatever you want. Once the package or environment is installed it open the gates for normal user access to.
In a new windows system it is always a good idea to use cmd with administrator access to avoid these errors
Upvotes: 0
Reputation: 11
To overcome this run py -m venv env --user
or you can also manually run the script as administrator
Upvotes: 0
Reputation: 11
This solved my problem:
python -m pip install -U pip --user //In Windows
pip install -U pip --user //Linux, and MacOS
Upvotes: 1
Reputation: 558
I work with 2 versions of Python 3.8 and 3.9. After changing my python.exe file to python38.exe I encountered this error. I searched and found this answer:
It looks like you might have renamed your python.exe executable to python3.exe? I got this same error after following install instructions that had me rename python.exe to be version-specific. I renamed it back and python -m venv venv worked fine.
I changed back my 2 main python files to python.exe and now I just run
py -3.8 -m venv env
or
py -3.9 -m venv env
Upvotes: 19
Reputation: 71
I have realized whenever there is issue with multiple installation, especially the ones that occur rarely like setting up environment, I use full path to the python installation
[path to python installation folder]/python.exe -m venv env
Point to note here is that if you have a copy of python.exe named python2/3/27/37.exe be sure to call the original executable.
Upvotes: 7
Reputation: 351
On Windows 10, you just need to run the script as an Administrator.
Upvotes: 2
Reputation: 311
I was facing the same problem. I found out that this is caused by renaming a copy python.exe executable to python3.exe. I did that because I have installed both Python 2.7 and Python 3.9 and configured environmental variables to use Python 2.7 with python command and Python 3.9 using python3 command. So that my paths in environmental variables of Python 2 were above Python 3.
To fix this edit your path variable so that Python 3 path will exist before Python 2 path.
Also if you are using Python2 also, go to the installed location and create a copy of python.exe executable and rename it as python2.exe.
Then when you run python command it will direct to the Python 3 and to use Python 2 you can use python2 command.
You can find more information on this by following this issue.
Upvotes: 25
Reputation: 661
I found out that Windows Defender now has a feature that blocks access/changes to system files. It added my documents folder by default, somehow preventing me from creating any folders in CMD despite having Admin Access. I hope this helps someone else!!
In short -- you may have to revise or disable your Windows 10 "Ranswomare Security Protection" setting to allow you to write files to your directories.
Upvotes: 26