For the last 3 days, I have been trying to set up virtual Env on Vs Code for python with some luck but I have a few questions that I cant seem to find the answer to.
Does Vs Code have to run in WSL for me to use venv?
When I install venv on my device it doesn't seem to install a Scripts folder inside the vevn folder. Is this out dated information or am I installing it incorrectly. I am installing onto Documents folder inside my D: drive using python3 - m venv venv. The folder does install and does run in WSL mode but I am trying to run it in clear VsCode so I can use other add-ons such as AREPL that doesn't seem to like being ran in WSL.
For extra context I have oh-my-ZSH set up and using the ubuntu command line on my windows device. Any information will be helpful at this point because I am losing my mind.
venv folder in side D: drive
result
If you have the python extension installed you should be able to select your python interpreter at the bottom.
You should then be able to select the appropriate path
Run Set-ExecutionPolicy Unrestricted -scope process before activating virtual environment.
All the best
You don't have to create a virtual environment under WSL, it will work anywhere. But the reason you don't have a Scripts/ directory is because (I bet) you're running VS Code with git bash and that makes Python think you're running under Unix. In that case it creates a bin/ directory. That will also confuse VS Code because the extension thinks you're running under Windows.
I would either create a virtual environment using a Windows terminal like PowerShell or Command Prompt or use WSL2.
I am connected to a machine running Windows 8 from my linux machine using OpenSSH. I need to download python3 on the Windows machine but I only have access to the command prompt, not PowerShell. I also have sftp set up, but all the python downloads are installers which don't work through the command prompt. Does anybody know what I can do?
You can download using the curl program, if it's installed on your windows machine. Something like:
curl https://www.python.org/ftp/python/3.8.3/python-3.8.3-amd64.exe -o python_install.exe
(or look for the Python version you want at https://www.python.org/downloads/windows/)
Then, you can run:
python_install.exe /quiet
There are also zip file packages you can download from the URL above.
Note that a quiet install may not change your system's PATH, so you may need to locate the directory in which Python was installed, and call the program from there.
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.
I have an account on a Linux server which currently has Python2.4 installed on it so by default running the command which python returns /usr/bin/python
I have installed Python2.7 in my account home directory # /path/to/myaccount and have set and sourced the path in my .bash_profile file as
PYTHONPATH=/path/to/myaccount/bin/python
export PATH=$PYTHONPATH:$PATH
However I am still getting Python2.4 as my default Python.
PYTHONPATH tells Python where to look for modules and packages (.py files etc)
You need to make sure your shell is looking in the right place for the Python binary
export PATH=/path/to/myaccount/bin:$PATH
In the Python installation on my PC there is a sweet script in C:\python26\tools\scripts called redemo.py. It's a simple tk application for testing regular expressions.
I wish I could get it--or something like it--running on my Mac, but I don't know how. The script doesn't appear to be part of the Python installation on my Mac. Ideas?
You can view the script directly from the python svn repository here and can download it:
curl http://svn.python.org/view/*checkout*/python/trunk/Tools/scripts/redemo.py?content-type=text%2Fplain > redemo.py
/usr/bin/python redemo.py
It seems to work just fine as is on OS X 10.6 with python 2.6.
Firstly, we should check whether the redemo.py is included in our system by using:
find / -name redemo.py # you can change the root searching path from `/` to other folder if you know the more specific path where python is installed.
Because some python distribution provider (e.g. Anaconda or default python in Linux/Unix distr.) sometimes will exclude this demo tool when install the python in our system.
If we found the redemo.py file within some python environments (assuming we have more than one python installed) then we can run it directly:
/right/path/python /right/path/redemo.py
But if there is no redemo.py file found in our system, we can still download this demo tool from official code repo (now at GitHub) and play with it.
curl https://raw.githubusercontent.com/python/cpython/3.6/Tools/demo/redemo.py > redemo.py
python redemo.py # Note the version is 3.6 in download path.
Mac OS X comes with Python pre-installed. As of 10.6.2 it has Python 2.6.1 found at /usr/bin/python. Copy redemo.py to your Mac. Make sure you have X11.app running and open a terminal (Terminal.app is available by default) and just run:
% python /path/to/redemo.py
Assuming there aren't any Win32 specific hooks in this script, it should execute.
Install Python on your Mac, then copy the script over? It should work fine on any Python installation.
Python is part of OS X, but sometimes it's a bit out of date: http://www.python.org/download/mac/