Trying to test Python on Win 10, getting Errno 2. Path to python is given to the value of env variable - python-3.x

I've installed Python 3.8 on Win 10 machine. Path to Python is C:\Users\userid\AppData\Local\Programs\Python\Python38\
Path environment variable values are: C:\Users\userid\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\userid\AppData\Local\Programs\Python\Python38\python.exe
In order to test python, I created a simple script called "script.py" in directory C:\python_scripts.
Then I tried to run "script.py" from the directory where it is located, but got error:
C:\python_scripts> python script.py
C:\Users\userid\AppData\Local\Programs\Python\Python38\python.exe: can't open file 'script.py': [Errno 2] No such file or directory
What might be the cause of getting this error? i tried to run the script with both cmd and powershell, with the usual user rights and with elevated admin rights, still getting Errno 2.
No other versions of Python have been previously installed on this machine (which is a corporate one, if that might be significant)
Thank you

Thank you #OferSadan for your suggestion to use dir command, it helped me to solve the problem. The "script.py" had an additional .txt extension added to it for some reason, but the Windows explorer only showed .py extension by default. Now I deleted the trailing .txt suffix and the script runs

Related

Why does cmd and powershell recognize "python" but not "py"?

I seem to be having the opposite issue as this user in this question. I can run python successfully, but py does not work for me. Overall, this is not a big deal but when I try to run code in VS Code, I get the error below:
py: The term 'py' is not recognized as a name of a cmdlet, function, script file, or executable program.
How can I either make VScode run python or change my system to accept py?
When I first downloaded Python, it was not placed into the path but I was able to fix that. I also confirmed that VS Code has selected the correct interpreter for Python in the same place.
EDIT: IMAGES
Path directory
Path used in enviroment
When you write "python" on CMD or Powershell, it checks the given keyword("python" here) in all the directories in Environment Variables.
In the case of python, the directory mentioned for python in Environment Variables > Path, you will find "python.exe" and not "py.exe".
So your cmd or PowerShell recognizes python and not py.

Run Python script from the Commandline using a certain Python installation

So far, I couldn't find out how to solve the following problem:
I have Python 3 installed under Windows 8.1. In addition to this Python installation, I have several other installations that came with programs such as QGIS and ArcGIS Pro. Those programs have their own Python installation with a Python exe shomewhere in their program folders.
Now I have a Python script that relies on some modules that are installed for QGIS Python. I want to run the script from the command line (or from within R). However, the script will be handled by my main Python installation that doesn't have the modules.
I tried to add some paths to the PATH and PYTHONPATH variables following instructions I found on the internet, but this only resulted in my Python IDE (Spyder) not starting anymore.
PATH:
C:\Users\Manuel\Python\Scripts\;C:\Users\Manuel\Python\;C:\Users\Manuel\AppData\Local\Programs\Python\Launcher\;C:\Users\Manuel\AppData\Roaming\TinyTeX\bin\win32;C:\Perl64\site\bin;C:\Perl64\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\MiKTeX 2.9\miktex\bin\x64\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\IBM\SPSS\Statistics\24\JRE\bin;D:\x2go\PuTTY\;C:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files;C:\Program Files\snap\bin;C:\Program Files\Inkscape\bin;D:\Program_Files\gdal\bin;C:\Users\Manuel\AppData\Local\GitHubDesktop\bin
PYTHONPATH:
C:\Program Files\Spyder\pkgs;C:\Users\Manuel;C:\Program Files\QGIS 3.14.16\apps\qgis\python\plugins;C:\Program Files\QGIS 3.14.16\apps\qgis\python;C:\Program Files\QGIS 3.14.16\apps\Python37
I also tried to replace "py" in the command prompt with C:\Programme\QGIS 3.14.16\bin\python3.exe, which also didn't work (Error: Access denied).
I tried this tutorial to import the modules within python, bit it gives
ImportError: DLL load failed while importing _core: Module not found
How can I tell the command prompt to use a specific Python installation in this single case (I want to use the other Python installation in every other case)?
I would do exact what you tried: "I also tried to replace "py" in the command prompt with the entire path to the QGIS Python exe, which also didn't work (Error: Access denied)."
But try to run it in a powershell with administrator privileges.

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.

can someone help me get python to run my scripts in CMD in windows 10 without having to cd to exact path each time.?

I'm trying to get python to run my scripts via CMD line.
note: idr if the book said where (a specific place to store my files for) python to access them but scanning back over the beginning I didn't find any relation to it.
According to this book https://automatetheboringstuff.com/2e/appendixb/ I am supposed to be able to type python (script.py) in command line just like this and it should run the script:
Here's the error I am getting upon execution, compared to the example from the book below it to show that this is supposed to work.
CMD LINE OUTPUT :
Microsoft Windows [Version 10.0.18362.1016]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\Armagon>python conway.py
python: can't open file 'conway.py': [Errno 2] No such file or directory
C:\Users\Armagon>
As you can see I get a python Error and researching this has given me nothing I found useful.
Here is the exact sample quoted from the book:
Microsoft Windows [Version 10.0.17134.648]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Users\Al>python hello.py
Hello, world!
C:\Users\Al>
First off, doing some research I have found a way to make it work, by cd(change directory) to the direct path of the folder containing the scripts C:\Users\Armagon\Desktop\mystuff. This helps to verify that the script I am trying to run is in fact located there and I've spelled it correctly.
But, according to everything I've followed up to this point I shouldn't have to do it this way.
The scripts are on my desktop all in the same folder called mystuff.
Following this link as well as a video Add a directory to Python sys.path so that it's included each time I use Python
I added the mystuff folder to PYTHONPATH in environment variables exactly as suggested. Here is a partial output of the sys.path (ran from IDLE) that shows mystuff filepath is added, so I'm pretty sure I did that part right.
['', 'C:\\Program Files\\Python38\\Lib\\idlelib', 'C:\\Users\\Armagon\\Desktop\\mystuff']
Maybe I've confused what is supposed to be happening here
I am operating under the assumption (based off what I've learned so far) that when CMD executes the line: python (script).py
It's supposed to run python.
Which in turn python is supposed to find my scripts on desktop (by the PYTHONPATH environment variable I created) and execute the script typed in CMD.
I've tried a lot of things in the process of getting just this far. I'd really appreciate if someone could point out what it is I'm overlooking to run python scripts from my desktop just like the book. I'm not very skilled at present and will gladly add any information as needed if I have excluded pertinent info I apologize in advance.
You should be able to do this as long as the script is in the module search path, for example, the PYTHONPATH environment variable. You should then be able to run the script like this:
python -m script
Well, the cd way is the way to go to run a python file via the command prompt. There is no other way I can think of.
Follow these steps or this link -> https://www.wikihow.com/Use-Windows-Command-Prompt-to-Run-a-Python-File to do it:
1)Open command prompt. type cmd or command prompt in search bar or run and press enter key.
2)In command prompt, given that the folder you are trying to access is in desktop, type-> cd desktop\myStuff.. Press enter.
3)Just write- python filename.py and enter.
4)It should run automatically.

Running pyinstaller in a command prompt returns "failed to create process"

I am trying to convert my python file into a .exe, and I found out about pyinstaller. I ran in the command prompt:pip install pyinstaller. After a few seconds, the last line said something like "pyinstaller was successfully installed" then when I am running just "pyinstaller" in the command prompt, it prints "failed to create process.". I tried running it in the directory with the scripts, I tried doing "pyinstaller myprogram.py" in the directory of my program. I even went to windows 10, "Advanced system settings" and added the directory of my python scripts, but it always returns this "failed to create process." I looked at other questions in stackoverflow. I even looked at the first lines of scripts of the pyinstaller but they already had quotes, so I do not know what is wrong.
Any reply would be appreciated.
It seems that this is a known issue with cx_Freeze which has been resolved in the source. It will be fixed in the new release (5.1.1)
I had the same issue so I checked the file
C:\Python27\Scripts\pyinstaller-script.py
and there was an old python path which when I installed python installer
C:\Python27\python.exe
But later I renamed python.exe --> python2.exe, so I just changed the path
C:\Python27\python.exe --> C:\Python27\python2.exe
in file
C:\Python27\Scripts\pyinstaller-script.py
and it worked perfectly.I would also suggest check you environemnt variables too carefully.

Resources