Python 3.9 virtual environments with windows 10 - windows-10

I faced this silly problem since the last 2 days, and it turns me mad.
Since I installed python 3.9 on my new Windows 10 machine, when I run the command python3 -m venv .\venv, I get the error "Python was not found; run without arguments to install from the Microsoft Store, or disable this shortcut from Settings > Manage App Execution Aliases."
If I switch off the app execution aliases, as mentioned in the message, I got a message:
'python3' is not recognized as an internal or external command,
operable program or batch file.
So, I looked at similar issues on Stackoverflow and fixed the path in the environment variables (in the user variables and in the system variables).
I added to the variable 'paths' the 2 following entries:
C:\Users{myuser}\AppData\Local\Programs\Python\Python39
C:\Users{myuser}\AppData\Local\Programs\Python\Python39\Scripts\
In all cases seen on Stack, that should have been enough. Not in my case.
I rebooted my machine twice, to make sure the new variables were picked up, but it's still the same.
I must add that I am using daily my Jupyter Lab environment, and everything works fine.
It's just this venv that refuses to work.
Does anyone has a hint on other places I should look for ?

Solution found thanks to Michael Vine.
To summarize:
referring to python instead of python3 in the command line
using [virtualenv venv] instead of [python -m venv .\venv] as I did

Related

What is the cause of "Bad Interpreter: No such file or directory"?

I have a Python virtual environment on my linux machine. It has been working fine for two weeks, but all of a sudden I woke up today, and while in the environment I can't execute any commands. For example, if I try to use pip list, or jupyter notebook, this is what I get (env is the name of my environment):
~/env/bin$ pip list
-bash: /home/ubuntu/env/bin/pip: /home/ubuntu/env/bin/python: bad interpreter: No such file or directory
The same thing happens with basically any other command, except Python. Typing python brings up the Python shell just fine. Interestingly it says Anaconda though, when I only used pip with this environment.
I've tried to find info on this but they all seem to be pertaining to running scripts.
Edit: Also want to mention that when I manually look in the environment bin, the packages I installed are all there in green, except Python is in red.
Thank you in advance.
You have a script /home/ubuntu/env/bin/pip and the script has shebang #!/home/ubuntu/env/bin/python but the file is either absent or is not executable.
Check if the file /home/ubuntu/env/bin/python exist. Check if it can be executed by the current user (just run it from the command line). If not — you need to find out a working executable (for example, it could be /home/ubuntu/env/bin/python3), edit the first line of /home/ubuntu/env/bin/pip to fix the shebang.

Issues with Path, installing packages, Conda environments, and several built-in commands

I've recently upgraded my PC with various bits and pieces and installed Windows 10 Pro. Most of what I do is data science related, but that's irrelevant.
I've had several issues with Anaconda 3 installations, my Path variables, installing various packages, and several Windows commands that I understood to be built-in:
Obviously, virtual environments are popular, and I've been using conda environments to run basic code without issue, however, several very key libraries are giving me issues when I try to install them. The first one I ran into an issue with was the very standard and presumably easy-to-install matplotlib, however, the issue I ran into here and am still getting is that chcp is not recognized as an internal or external command.... When I run where chcp as admin I have no issues. chcp will run without error as well, but as soon as stop cmd as admin, chcp nor where commands work whatsoever. I don't get it. I've done just about everything I can to the Path variable that I've seen online, and nothing has worked. Uninstalled and reinstalled. Nothing has changed.
Furthermore, isn't Anaconda supposed to come pre-installed with these?
note where does not return an error that would indicate that it's looking in the wrong directory; I get an exit code DNE 0 due to the command apparently not existing outside of admin privileges in \System32. Makes no sense to me and haven't found anything like this/ a vague resemblance of a solution elsewhere.
So with all of that in mind:
what might be causing this issue? Permissions? Locations? Something I'm missing from the Path variables? etc. Fixing the issue with chcp should do it for me.
How can I get the Anaconda "package" to, well, work? -> I can get the launcher, Jupyter notebooks, etc., but what I'm referring to here is the set of packages for Python itself -- that's why I went for Anaconda to begin with.
Thanks in advance.

Specify Python3 to Atom on Windows 10

In advance, sorry if this is question ought be on SuperUser or another site
The python3 shebang doesn't seem to work on win10. (I cant check right now, but I believe the analogous approach worked on MacOS for me last night). Consider the following
#!/usr/bin/env python3
print("hello world")
Leads to the error 'python' is not recognized as an internal or external command,
operable program or batch file. This makes sense because I only have a python3 distro on my machine (which can only be called like python3). However, Atom seems to be ignoring the shebang altogether. FYI, I'm running the script with the popular "script" atom package.
I've tried the permutation, #!/usr/bin python3, but this doesn't work either.
I've tried permutations
I'm still interested in how shebangs work within the Atom environment, but as far as getting python3 up and running, you dont need a shebang. You can simply change a config file (python.coffee) from within Atom, then relaunch. See Daniel Chamorro's excellent answer here: How to setup Atom's script to run Python 3.x scripts? May the combination with Windows 7 Pro x64 be the issue?

I don't understand the error I get while activating environment in Anaconda

I reinstalled Miniconda (version 4.3.21) at c:\Miniconda3, created an environment named data and also installed some packages in this environment. The Python version came with this Conda is 3.6. However, before installing the Miniconda, version 3.4 of Python was already installed on my system (location c:\python34). OS is Windows 7 (32 bits).
On command line, I can run command like conda info --envs or conda create -n data. I can even open Python IDLE by running idle command which opens the IDLE for Python which came wih Miniconda. But when I try to run activate data, it shows this error.
However, when I run command line as administrator, I am able to activate environment. If I remember correctly, earlier I was able run all commands without needing any admin privileges. Why does this happen?
So what is happening is that your user likely has the original Python executable(or old Miniconda Python) in your users PATH and this is found before Minconda Python. When run as Admin(because installing to C:\Miniconda requires admin privileges) it finds the correct executable that is in the System PATH. Having both a standard Python and Miniconda in your user Path will cause issues as it will use the first Python.exe found based on your PATH.
Check Computer > Properties > Advanced System Settings > Environment Variables.
Put Minconda before the standard Python or remove the standard python(there is no difference between standard python and the python included with Miniconda as they both come from python.org). You may also need to set the permissions on the entire C:\Miniconda directory for your user. Even though you have admin access you will still need to escalate privileges if you don't set permissions for your actual user.

'python3' is not recognized as an internal or external command, operable program or batch file

I am using Python 3.5.2 version on Windows 7 and tried using python3 app.py. I am getting this error message:
'python3' is not recognized as an internal or external command,
operable program or batch file.
Is there any specific cause about why the python3 command is not working?
I also verified that the PATH is added to environment variables.
There is no python3.exe file, that is why it fails.
Try:
py
instead.
py is just a launcher for python.exe. If you have more than one python versions installed on your machine (2.x, 3.x) you can specify what version of python to launch by
py -2 or
py -3
You can also try this:
Go to the path where Python is installed in your system. For me it was something like C:\Users\\Local Settings\Application Data\Programs\Python\Python37
In this folder, you'll find a python executable. Just create a duplicate and rename it to python3. Works every time.
Python3.exe is not defined in windows
Specify the path for required version of python when you need to used it by creating virtual environment for your project
Python 3
virtualenv --python=C:\PATH_TO_PYTHON\python.exe environment
Python2
virtualenv --python=C:\PATH_TO_PYTHON\python.exe environment
then activate the environment using
.\environment\Scripts\activate.ps1
Yes, I think for Windows users you need to change all the python3 calls to python to solve your original error. This change will run the Python version set in your current environment. If you need to keep this call as it is (aka python3) because you are working in cross-platform or for any other reason, then a work around is to create a soft link. To create it, go to the folder that contains the Python executable and create the link. For example, this worked in my case in Windows 10 using mklink:
cd C:\Python3
mklink python3.exe python.exe
Use a (soft) symbolic link in Linux:
cd /usr/bin/python3
ln -s python.exe python3.exe
In my case I have a git hook on commit, specified by admin. So it was not very convenient for me to change the script (with python3 calls).
And the simplest workaround was just to copy python.exe to python3.exe.
Now I could launch both python and python3.
If python2 is not installed on your computer, you can try with just python instead of python3
For Python 27
virtualenv -p C:\Python27\python.exe django_concurrent_env
For Pyton36
virtualenv -p C:\Python36\python.exe django_concurrent_env
Enter the command to start up the server in that directory:
py -3.7 -m http.server
I had a related issue after installing windows 11, where python3 in cmd would open the windows store. I was able to sort it out between this post and this other one. In short, I reinstalled python and made sure to add it to PATH. Then, in settings, Apps > Apps & Features > App Execution aliases. Here, all I had to do was make sure that every single python .exe (including idle and pip) were turned off EXCEPT FOR the python3.exe alias. Now it works like a charm.
FWIW:
The root of this issue is not with you or with python. Apparently, Microsoft wanted to make installing python easier for young kiddos getting interested in coding, so they automatically add an executable to PATH. For those of us that already have this executable, it can cause these issues.
Found out instead press the play button the top right and it should work in visual studios:
Do not disable according to first answer
Saying python3 in the command will not work by default.
After figuring out the problem with the modules (Solution): https://youtu.be/paRXeLurjE4
Summary:
To import python modules in case of problem to import modules:
Hover over python in search:
Click open in folder
Hover over and right click
click properties
copy everything in path before \python.exe
close those windows
For cmd (administrator):
cd --path that was copied--
then python -m pip install --upgrade pip
cd Scripts
pip install "Name of Package" such as pip install --module (package) --
Im on win10 and have 3.7, 3.8 and 3.10 installed.
For me "python" launches version 3.10 and does not accept commands (like -3.7), "py" launches newest version but does accept commands, and "python3" does nothing.
Uninstalled 3.10 and "python" now does nothing, and "py" launches 3.8.
I am unable to add a comment, but the mlink option presented in this answer above https://stackoverflow.com/a/55229666/8441472 by #Stanislav preserves cross-platform shebangs at the top of scripts (#!/usr/bin/env python3) and launches the right python.
(Even if you install python from python.org, Windows will direct you to the app marketplace nowadays if you type python3 on the command line. If you type python on the same cli it will launch the python.org version repl. It leads to scripts that generate no output, but more likely silently failed completely. I don't know ho common this is but have experienced it on a couple of different devices)
If you have this at the top of your script to ensure you launch python3 and don't feel like editing everything you own, it is not a bad approach at all... lol.

Resources