This issue has been solved, resulted in a bug report to Python.org. See the my self-answer below for the workaround until it's fixed in a future release of Python
One of my PCs got bitten by this bug which no longer allows me to create venv with the error:
Error: Command '['C:\\Users\\kesh\\test\\.venv\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 101.
This issue has been known, chronologically: v3.7.2, v3.8, v3.?, & v3.10.1
The only known solution is to give up per-user install and use global install by checking "Install for all users" option
I'm trying to figure out what exactly is happening, but quickly running out of ideas. Here are what I've tried so far:
On my PC, "Install for all users" works as well as per-user install on a dummy account (all using the same v3.10.2 installer). This singles out the issue to be on my Windows account. Changing the install location does not help.
Went into venv source by running Python with venv.main(args=('.venv',)), debugging line-by-line and noted that it copies Lib\venv\scripts\nt\python.exe from the python install dir to the local .venv\Scripts folder using shutil.copyfile().
If I run the original Lib\venv\scripts\nt\python.exe in command prompt, it runs with a message No pyvenv.cfg file (which makes sense as the .cfg file is in .venv folder which it couldn't see)
If I call the copied .venv\Scripts\python.exe then it returns an error Unable to create process using 'C:\Users\kesh\AppData\Local\Programs\Python\Python310\python.exe' (note that the python.exe path for the process is that of the installed Python exe)
If .venv is installed successfully (on the dummy Windows account), the above run starts a Python session as you'd expect.
venv\scripts\nt\python.exe is different from the standard python binary and verified that this file and its source in venv\Scripts\nt are identical.
All this points to that something in my account configuration is bothering the .venv\Scripts\python.exe to do the right thing, but my environmental variables are pretty clean and python paths are at the top of the user PATH variable.
Currently trying to locate the source code of .venv\Scripts\python.exe but not found it yet.
Can it be something in registry?
If you have any other ideas to try, please share.
Update #1:
Found the source of the error message PC/launcher.c Line 814
Possibility: CreateProcessW(NULL, cmdline,... where cmdline is the original python path in the error message, without quote. CreateProcessW documentation states executable name is deduced from the first white space–delimited token in the cmdline string. Though I replaced my actual account name with kesh it actually comprises two words and a space...
Update #2:
Solution found as posted below
Bingo, the finding in the update #1 was the cause. The space in my username was the culprit. Although I have no idea what triggered this behavior change on my account... (anybody with an answer, please follow up.)
Let's say the per-user python is installed at
C:\Users\User Name\AppData\Local\Programs\Python\Python310
In my case, "Microsoft Visual C++ 2015-2022 Redistributable" installer (VC_redist.x64.exe) left a log file C:\Users\User (a text file with the first part of my account name as its file name). This caused python venv to use C:\Users\User as the python executable and promptly failed (see the issue tracker link below for the full explanation).
You can fix the issue in 2 ways until Python patches the problem.
Easy Fix
Simply delete the file C:\Users\User
Note: This will work until next time another installer leaves this nasty log file.
More Involved Fix
In command console, run
DIR /X C:\Users
which lists something like:
02/08/2022 11:44 AM <DIR> .
02/08/2022 11:44 AM <DIR> ..
11/19/2020 01:48 AM <DIR> Public
02/08/2022 02:47 PM <DIR> USERNA~1 User Name
Open the Environmental Variables dialog and edit Path user variable's Python entries from
C:\Users\User Name\AppData\Local\Programs\Python\Python310\Scripts
C:\Users\User Name\AppData\Local\Programs\Python\Python310
to
C:\Users\USERNA~1\AppData\Local\Programs\Python\Python310\Scripts
C:\Users\USERNA~1\AppData\Local\Programs\Python\Python310
Re-open python console window or app so the path change is applied to your dev environment.
Note: This fix will work as long as you don't update python version. When you do, you need to delete the old path entries manually and update the new path entries.
Eventual Fix
I reported this bug to python bug tracker: Issue 46686. They've acknowledged the bug and have it labeled as critical with a proposed fix. So, hopefully it will get fixed in a near future release. (>3.10.2)
Related
I'm unable to use python within the virtual environment. Python works fine outside of the virtual environment. I'm using Python 3.10.2
I keep on getting the error below when trying to run any python commands.
'C:\Users\User\AppData\Local\Programs\Python\Python310\python.exe'
It might be relevant to mention that I was unable to create the virtual environment through the 'python -m venv env' command. Error generated was
Error: Command '['C:\\Users\\User\\Documents\\Python Projects\\PDFtoText\\env\\Scripts\\python.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 101.
I had to add 'without-pip' to the end of the command to create the virtual environment. Weird thing is, I was able to use pip within the virtual environment without having to manually install it.
The path to python is in the environmental variables.
I tried reinstalling python but that did not help.
Lastly, all these errors started occurring after I downloaded Visual Studio Community 2022.
Short answer, I bet you have a space in your Window's account name (say Your Account is where your account is saved so you have C:\Users\Your Account folder, and there is also a text file C:\Users\Your ("Your" being the first part of your user name). MSVS2022 (maybe earlier versions, too) is known to leave this log file which exposes a bug in Python venv's python launcher. Delete this text file, and your problem should be solved.
See my question/answer for more details.
I am getting the following error message when attempting to execute Python code in PyCharm:
Cannot run program "/Users/x/.virtualenvs/untitled/bin/python" (in directory "/Users/x/PycharmProjects/untitled"): error=2, No such file or directory
I made sure everything was updated and restarted my computer, but I still get the same error. I have no idea what the problem is.
Edit
I just opened my terminal and was faced with this error message:
virtualenvwrapper_run_hook:12: no such file or directory: /usr/local/bin/python3.7 virtualenvwrapper.sh: There was a problem running the initialization hooks.
If Python could not import the module virtualenvwrapper.hook_loader, check that virtualenvwrapper has been installed for VIRTUALENVWRAPPER_PYTHON=/usr/local/bin/python3.7 and that PATH is set properly.
I have no idea what happened here. I certainly didn't touch any of this.
Edit 2
If I execute Python3 --version, I get Python 3.8.5.
Edit 3
I followed this, but this error remains:
Edit 4
This is the current state:
I think this is related.
If it helps at all this is what my venv settings looks like.
I don't have the answer as to why it happens, but I find its usually when renaming the project.
In the past i've recreated the project and copied the project files directly from the old folder to the new one in a file explorer (not pycharm) and its fixed it.
This Error Occurs because when you rename the file you need to update the file path name also...
.......Solution...........
click on Edit Configurations (near the green 'run' play button)
Where it says 'Script Path' at the end of the string is where you find the name of
your file
Change the name to the updated file name
Probably the root library has been deleted or corrupted.
I suggest to delete the venv library in explorer and then write the following commands in the terminal
> C:\Users\MY\PycharmProjects\pythonProject>py -m venv venv
> C:\Users\MY\PycharmProjects\pythonProject>cd venv\Scripts
> C:\Users\MY\PycharmProjects\pythonProject\venv\Scripts>activate
For me, it was the symbolic link in the project. Running this command fixed it:
xcode-select --install
You may want to check the contents of the 'activate' script inside your venv. It contains a few hardcoded, absolute paths to files and directories within your environment. If you change something in that environment, e.g. move a file or directory around, these paths can easily become invalid.
Similar issues can arise when you, for example, create a virtual environment inside a virtual machine, then open files in PyCharm from outside that machine.
For me, the problem was that I created the virtual environment through the PyCharm settings and ticked "Inherit global site-packages", I think. Once I removed the virtual environment and created it using the old fashioned way, i.e.
mkvirtualenv projectname --python=python3.10
everything fell into place.
I have been trying for hours to install SCons on my Windows 8.1 machine and simply cannot. I honestly have no idea whatsoever what I'm doing wrong, or really what I'm doing in general. Here is the step by step process of what I have done
1: installed Python 3.7 from www.python.org I used the python-3.7.3-amd64.exe to install it, it seems to have worked (I have never used python before so if anything is off I wouldn't realize it). When I use the command console and input 'python --version' it outputs 'Python 3.7.3'
2: I downloaded scons-3.0.5.zip from www.scons.org I followed the website's instructions as best I could. I used 7zip to extract it's contents into a new file called 'scons-3.0.5' located at C:\ It's complete path, therefore, is C:\scons-3.0.5
3: I ran Python 3.7 as an admin. I inputted '# cd scons-3.0.5' just as the scons website says to do. It outputted nothing, and I noticed that the new line started with '...' instead of '>>>', I have no previous experience with Python so I don't know if that's good or bad. I then continued to follow the instructions by inputting '# python setup.py install', it outputted nothing, and once more the new line started with '...'. I hoped that was all I needed to do but in the command console I inputted 'scons --version' (I read somewhere this can be done to check if it is installed), it outputs "'scons' is not recognized as an internal or external command, operable program, or batch file.". This, combined with the fact that seemingly nothing is different, leads me to believe it has not been installed.
4: I tried to do something a bit different. I noticed that the zipped file I downloaded from the scons website contained 2 files in it, 1 being scons-3.0.5, the other being pywin32-master.zip, I had both of these in the file C:\scons-3.0.5 I decided to delete that file, and in its same location place the scons-3.0.5 file. Now instead of C:\scons-3.0.5 including scons-3.0.5 and pywin32-master.zip it contained just the contents of the scons-3.0.5 file that was in it before (if that makes sense, I might clean it up in the morning and make it easier to read). I once more did step 3, and the results were no different.
I have no idea what I'm doing, I have no prior experience with Python or the command console, I just want to set up scons and never use Python again. Does anyone know how I can fix this? I have googled for hours but it seems as if I'm the only one who's having this issue.
The contents of the zipped file from scons website:
contents of the scons-3.0.5 file in the zipped file
I doubt the images will help but I have included them just in case if they seem off
edit: I did know what installing via Pip was, but I googled it and it worked just fine! Thanks to Alexander Lopatin and bdbaddog for the help
So you're mistake is in step 3.
I ran Python 3.7 as an admin. I inputted '# cd scons-3.0.5'
The website says:
# cd scons-3.0.5
# python setup.py install
Notice this is
cd into the unzipped directory
THEN run python setup.py install
Instead you've run python, then typed a shell command into python. Which is why you had issues.
Note: On windows you shouldn't need to run as admin to install SCons.
Although as #dirkbaechle said. Pip is the preferred method to install python.
python -mpip install scons
But if you'd rather follow the instructions. Just bring up a windows command shell, or powershell if you like, cd into the unzipped directory, and run python setup.py install
BTW. There's an IRC channel and a users mailing list for SCons support.
https://scons.org/contact.html
On git bash, I receive a command not found message for python, r and nano.
I am on Windows 10. I do not know what I am doing wrong.
I type
r --version
python --version
nano --version
and they all return command not found.
I read something that had me try
alias python='winpty python.exe'
and it renamed python, but when I tried
touch .bashrc
it returned
touch: command not found
I followed the instructions in a Github course, PS239T. I have been fortunate, except for getting these three programs to work.
I tried
build/console.exe c:/Python36/python.exe
and it returned
build/console.exe: No such file or directory
I tried
PATH=$PATH:/c/Python36/
$ export PATH="$PATH:/c/Python36"
echo 'export PATH="$PATH:/c/Python36"' > .profile
and nothing.
I got Python 64-bit via Anaconda.
I tried setting up the Python 3.4 environment
conda create –n py34 python=3.4 anaconda
./python name_of_your_python_script.py
nothing.
which python
got me a huge directory path:
which: no python in (/c/Users/Edward/bin:/mingw64/bin:/usr/local/bin:usr
/bin:/bin:/mingw64/bin:/usr/bin:c/user/Edward/bin:/c/Program Files
(X86)/Intel/ 1CLS client:/c/Program Files/Intel/1CLS Client:/c/Windows
/System32:/C/Windows:/C/Windows/Sytem32/Wbem:/c/Windows/System32
WindowsPowerShell/V1.0:/c/Program Files/Intel/Intel(R) Management Engine
Components/Dal:/c/Program Files/Intel/Intel(R) Management Engine
Components/IPT:/c/Program Files (x86)/Intel/Intel(R) magament Engine
Components/IPT:/c/Program Files (X86)/Intel/Intel(R) Management Engine
Components/IPT:/c/WINDOWS/Syste,32/Wbem:/c/WINDOWS/System32
/WindowsPowerShell/v1.0:/c/Program Files (x86)/Rand McNally/RNDDock
/GtkSharp/2.12/bin/:/c/Program Files d/AppData/Local/Mircosoft
/WindowsApps:/c/Users/Edward/AppData/Local/Pandoc:/usr/bin/vendor_perl:
/usr/bincore_perl:/c/python36
I would have just put up the screenshot or copied and pasted it, but I do not know how.
I am sure I made an error somewhere.
I get the same type of results when I try to figure out what is going on with r and nano.
Update 1
Download and install 'Anaconda'
'https://store.continuum.io/cshop/anaconda/'.
Download the default Python 3 installer 'do not follow the link to version 2'.
Use all of the defaults for installation except make sure to check 'Make Anaconda the default Python.'
Install R by downloading and running
'this .exe file from CRAN'
'http://cran.r-project.org/bin/windows/base/release.htm'.
Also, please install the 'RStudio IDE'
'http://www.rstudio.com/ide/download/desktop'.
All you need is RStudio Desktop.
nano is a basic editor and the default that we use in this class. To install
it, download the Software Carpentry Windows installer
http://files.software-carpentry.org/SWCarpentryInstaller.exe'
and double click on the file to run it. 'This installer requires an active internet connection.'
Sublime Text is a more advanced editor. Download Sublime Text 3 'here'
'https://www.sublimetext.com/3'.
Update 2
I began trying janos advice and ran
/c/Python36/python.exe --version
and it returned
bash: '/c/python36/python.exe: No such file or directory.
I tried to run
PATH="/c/Python36:$PATH" python.exe --version
but it returned
bash: python.exe.: command not found
I tried to run
PATH="/c/Python36:$PATH" python --version
and it returned
bash: python: command not found
Update 3
janos told me I went too far without figuring out the problem, then told me to run
ls -l /c/Python36/python.exe
and it returned
ls: cannot access '/c/Python36/python.exe': no such file or directory.
janos told me to focus on the first error
bash: '/c/python36/python.exe: No such file or directory.
after entering
/c/Python36/python.exe --version
and so there I will focus.
janos asserted
Can you open a file explorer and navigate to C:\Python36, and see python.exe there? Probably not.
and is correct.
I ran
C/Users/Edward/Anaconda3/pkgs/python-3.6.3-h9e2ca53_1/python.exe
with no success.
I ran that in explorer and found that the publisher could not be verified.
Update 4
I went to
'python.org/downloads/release/python-363'
and downloaded 'Windows x86 embeddable zip file' and Unzipped it in
C/Users/Edward/Anaconda3/pkgs
it worked.
Thank you.
I bet I am having the same problems with 'r' and 'nano'.
I am going to run down the list again and perform all the check. I will do the same thing with 'r' and 'nano'.
Everything worked out for Python. I will do 'nano' and 'r' in due course.
I could not find
/c/python36/
so I used
/c/Users/Edward/Anaconda3/pkgs/python-3.6.3-embed-win32/
Update 5
janos is right again. I would need to create the python36 folder as it was not built automatically during the installation. janos' method worked on 'r' and 'subl' or sublime text 3. I gave up on 'nano'.
I found that some of my '.exe' files were in listing with spaces in the names. I moved to the user folder and eliminated any spaces.
I also downloaded version from the official website, and that too helped.
I could not figure out how to get 'nano' to work. I could not even find it on my pc. I used 'subl' instead.
Start from the basics. Try the simplest thing that can possibly work,
and make progress in baby steps,
from one sane state to the next.
The first step is to run a by entering its absolute path directly.
If the Python executable is at /c/Python36/python.exe, then run this:
/c/Python36/python.exe --version
This is very simple and it should just work.
If it doesn't, the command will give you an error message with clues.
A next step could be to simulate adding to PATH. Try this:
PATH="/c/Python36:$PATH" python.exe --version
This is one line. It sets a value to PATH in a way such that it's only active during the execution of the command. After the command completes, the value of PATH will be back to what it was before. This is a good way to test things. Also notice that I prepended to PATH the directory that contains python.exe, not the full path to python.exe.
That's an important point, this is how the PATH variable works.
It's a list of directories, and all executable files in those directories become easily executable by simply typing their name, without having to type their absolute paths.
Next, I would try this:
PATH="/c/Python36:$PATH" python --version
That is, see if you can drop the .exe from the name of the command.
I don't have Windows so I cannot test if this works.
And maybe it doesn't. (But I think it does.)
If everything worked so far, then the next step is to make the PATH setting permanent.
The way to do that is to put the command PATH="/c/Python36:$PATH" into a file that is always executed when you start a new Git Bash session.
If I remember correctly on Windows you can put it in ~/.profile
(a file named .profile in your home directory).
Where is ~? Here's one way to find it:
cd
explorer .
The above opens a file manager inside that directory.
You can use a plain-text editor like Notepad or Wordpad to edit it.
You can also use this shell command to append the line that updates PATH:
echo 'PATH="/c/Python36:$PATH"' >> ~/.profile
This line will get executed in all new Git Bash session.
Not in the current session,
because this file is only executed once.
If everything above worked, then in a new Git Bash session you should be able to run python --version.
If not everything worked, then you need to read the error message you get carefully, and not advance to the next step until the problem is resolved.
It's useless to advance to a next step when you are already not in a sane state.
You can follow the exact same logical process for all the other programs too.
ERROR: Python 3 is not supported by the Google Cloud SDK. Please use a Python 2.x version that is 2.6 or greater.
If you have a compatible Python interpreter installed, you can use it by setting the CLOUDSDK_PYTHON environment variable to point to it.
I guess the first question we should be asking is "with all the money google makes off of their customers why can't they hire someone to ensure that their cloud sdk works with python 3?"
How exactly to overcome this error on linux? What specific files need to be edited? and where should those files be located?
I searched around, a lot, and found this question about how to fix this on Windows, but the answer is not really that comprehensive.
Thus far I've attempted:
One source of documentationsays to modify a file called app.yaml, but I searched using the command find . -name "app.yaml" and no such file exists.
Specifically I'm using arch linux, I originally tried to use the AUR package but it's disfunctional.
So I installed from the documentation, making sure to edit the ./install.sh file, specifying python2 as per this discussion on the google groups, that doesn't work either. after running the command gcloud auth login I get the same error as posted above.
This is a very easy thing to solve. The native python command on the Arch command line is actually for Python 3. The SDK requires Python2.7 and the
Just go to the google-cloud-sdk folder and open the install.sh file.
Change the CLOUDSDK_PYTHON="python" value to CLOUDSDK_PYTHON="python2.7"
Rerun the install with the command ./install.sh in the same folder and follow the prompts.
That's all.
I had the same issue so I did a little change in the dev_appserver.py. This file is in the following path :
google-cloud-sdk/bin
change the shebang from /usr/bin/env python to /usr/bin/env python2
I see this almost every time I update gcloud SDK, especially when running dev_appserver.py <my app config yaml file>
I found that setting the CLOUDSDK_PYTHON env variable to 'python2' seems to silence the error. E.g on macOS:
export CLOUDSDK_PYTHON=python2
Not sure why they simply cannot make this dev server compatible with Python 3 already