I think I'm encountering a weird bug in Windows 8.1 trying to use django-admin.py (and any script really) in Powershell. I've successfully installed Python 2.7.6, and have added C:\Python27\ and C:\Python27\Scripts to my path.
When I try to use django-admin.py or python django-admin.py in Powershell, I get a file not found error.
Interestingly, when I use Command Prompt, I am able to use django-admin.py, even without the python prefix.
To execute scripts in Powershell, you need to set the execution policy to something other than restricted. For example:
Set-ExecutionPolicy RemoteSigned
This should allow general scripts (like .ps1 files) to be run. I still had problems running python files from the path so I added .py files to the PATHEXT variable. In Powershell:
$env:PATHEXT += ";.py"
I don't think this is permanent, so you may need to add it to your profile or change the environmental variables from the Advanced System Settings. This fixed the problem for me.
Related
I have been using Jenkins for a few years and recently bought a new Windows 10 PC. I installed Jenkins 2.89.2, Visual Studio 2017 and Python 3.6 and copied several Jenkins jobs from my previous Windows 7 PC.
The problem that I encountered was that all the python scripts in the free-style Jenkins jobs now do nothing.
I have similar command-line batch files which run these python scripts which work just fine in a command window on the new PC.
I have also checked the file associations with ftype, and ended up changing it:
ftype Python.File
Python.File="D:\Python36_64\python.exe" "%L" %*
My work-around is like this:
Example line which worked under Windows 7:
CreateBuildNumber.py <= uses PATH to find this file, then file associations to run python
Replacement line need to work under Windows 10:
python .\Scripts\CreateBuildNumber.py <= uses PATH to find python.
How can I avoid explicit paths in my scripts?
Update:
D:\project>assoc | findstr -i python
.py=Python.File
.pyc=Python.CompiledFile
.pyd=Python.Extension
.pyo=Python.CompiledFile
.pyw=Python.NoConFile
.pyz=Python.ArchiveFile
.pyzw=Python.NoConArchiveFile
echo %PATH%
D:\Python36_64;D:\Python36_64\Scripts;.\Scripts;"C:\Program Files\CppCheck";C:\windows\system32
Further Info
I removed .\Scripts from the %PATH% and re-ran the job, having also moved demo.py into .\Scripts, now instead of doing nothing there is the error:
'demo.py' is not recognized as an internal or external command, operable program or batch file.
This means that Windows IS looking for and finding python scripts, but is failing to execute them. Why would windows not take the next step and use file associations to find an executable program to run, taking the file as a parameter?
Update:
Now everything works as it should and I don't know why.
I recently started using a different job on Jenkins that I had neither run nor touched for over two years and that one just worked without modification. I have since gone back over the job in question and reverted all the changes and this one works as well.
My guess is that Windows 10 has been patched.
The fact that "demo.py" gives the message '...is not recognized as an internal or external command' doesn't convince me that your script is recognized as executable. If I type 'turkey.abc' into a command prompt window I get the same error, and I don't have a tool for executing '.abc' files.
I see two possibilities here:
1) In batch scripts, executable extensions sometimes must appear in an environment variable called PATHEXT.
In the Jenkins batch script, add a "set" command near the top of the script to dump the environment variables for your running script into your Jenkins build log (you can remove the set command after this is debugged). Run the build. Look not only for the definition of PATH, but also at PATHEXT. Is ".py" one of the extensions listed there?
I have experienced this problem with Perl scripts. However, I'm wimping out on claiming this definitely since in testing on my Windows 10 home PC I am successfully executing .py scripts even without it being in PATHEXT, so it's something to try but it may not be this.
2) Another possibility is that the environment in which your service is running is different than the environment you get when you open a command prompt on your desktop (because the Jenkins service runs as a different user than the one you log in as.)
Adding "set" to your Jenkins batch commands will help debugging this too, since it will show you the environment your Jenkins script is running in. Then you can examine PATH to see if your script folder is being found.
It is also possible that the file associations for Python were installed for your user only, not for all users (i.e., in HKEY_CURRENT_USER in the registry instead of HKEY_LOCAL_MACHINE). That is harder to dump into your Jenkins log - the 'reg' command would do it, but it will take you a number of tries to get everything you need. You might be able to figure it out by just examining the registry. Search for ".py" - if it occurs in HKEY_LOCAL_MACHINE that is not it; if it occurs in HKEY_CURRENT_USER that is at least part of the problem.
I don't know if this will fix your issue but you shouldn't have a relative path in your PATH environment variable.
Can you try again after having removing .\Scripts from the PATH variable? (don't forget to open a fresh new terminal do get the new %PATH% value)
The problem is that your PATH variable doesn't include the paths of you python scripts. You need the full path of the Scripts directory. Not the relative path .\Scripts.
so far I have been ok with debugging and running in a python debug terminal. Now that I'm being forced into functions, i have to input the arguments when launching the script, for example:
./python.py BIRTHDAY AHMED
and have it spit out something along the lines of this:
have a happy BIRTHDAY enjoy the day AHMED
problem comes down to me not knowing how to setup a terminal for such use. i have a bash terminal, however it wont recognize my python interpreter (#!/usr/bin/python3).
I added "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe" to my user settings to gain the bash terminal as well as installed Git.
Any ideas on how i can get a work in terminal that i can input arguments and recieve an output would be most appreciated. (running on windows 10)
You are providing the path of Git Bash, which only provides enough bash-like functionality to use git. That is why running .sh (Bash Scripts) or .py files doesn't work by default.
If you add python to your PATH environment variable, that will make it so running python.exe filename.py [ARGS] will work on the Integrated Terminal.
Another solution is to install WSL if you are on Windows 10, which does provide full* bash functionality under a modified Ubuntu shell. Then just provide VSCode the path to the WSL bash.exe. (How to here)
I have installed Python 3.5.2 on my windows 8 computer, I tried in cmd python --version and it gave me that stupid error:
"python is not recognized as an internal or external command..."
I also have no files named python on my computer anywhere. I used the search feature on file explorer and I've search manually. I even looked through the hidden files. I have tried to install Python 3 times and the same thing keeps happening. Any help appreciated.
In Windows 8 for Python 3.* I believe it is:
C:\Users\yourusername\AppData\Local\Programs\Python\
To use that from the Windows command line you will need to add it to your path.
Control Panel -> Advanced System Settings -> Environment Variables -> System Variables -> Path
Add in the Python path at the end after a semi-colon, do not delete the others.
You may try to use which python to find out the location of python in your computer. If it doesn't work and you cannot find where is the your installed directory, you may need to reinstall and make sure you remember the installation directory and add it as a environment variable in windows system.
I was probably same problem with python launcher.
In registry by regedit change
HKEY_CLASSES_ROOT\Python.File\shell\open\command from "C:\some\path\to\python" "%1" %* to "C:\Windows\py.exe" "%1" %*.
And first line of script shoud be:
#! python3
Now it shoud work properly and run in cmd just by scriptname, not scriptname.py, and not py scripname.py.
My command prompt is currently running Python 3.2 by default how do I set it up to run Python 2.7 by default, I have changed the PATH variable to point towards Python 2.7, but that did not work.
UPDATE:
It still does not work. :(
Still running python3 - to be specific it runs python3 when I am trying to install flask - which is what I want to do.
More generally, when I simply type python into the command line, it does nothing.
I get a 'python' is not recognized as an internal or external command, operable program, or batch file error.
No idea what to do.
If you call your Python scripts directly using python script.py then setting the PATH to have the 2.7 directory first should be enough.
If you want to call Python scripts indirectly with the shell, i.e. by writing just script.py or by executing the file from the explorer, you need to set the 2.7 installation as the default program handler for the .py extension. The easiest way to do that is to run the Python installer again and choose the option “make this installation the default”.
Note that with the new launcher, that ships with 3.3+, you don’t need this, as you can specify the version number using a shebang line and the launcher will automatically pick the appropriate interpreter.
Changing your PATH environment variable should do the trick. Some troubleshooting tips:
Make sure you didn't just change the local, but rather the system variable to reflect the new location
Make sure you restarted your CL window (aka close "cmd" or command prompt and reopen it). This will refresh the system variables you just updated.
Make sure you remove all references to C:\Python32\ or whatever the old path was (again, check local and system PATH - they are both found on the same environmental variables window).
Check to see if Python3.2 is installed where you think it is... (just rename the directory to something like OLD_Python3.2 and go to your CLI and enter "python" - does it start up? If it does is it 2.7? or 3.2? If not, you did something wrong with your PATH variable.
All else fails - reboot and try again (you might have some persistent environment variable - which I don't see how that can be - but hey, we are brainstorming here! - and a reboot would give you a fresh start.
If that doesn't work then I'd think you are doing something else wrong (aka user error). CMD has to know where to look for python before it can execute. It knows this from your PATH variable... now granted, I work almost exclusively in 2.6/2.7, so if they did something to the registry (which I doubt) then I wouldn't know about that.
Good luck!
Change the two las lines to you current python desired build path:
Windows Registry Editor Version 5.00
' Extracted from Python 2.7 silent installation By Elektro H#cker
[HKEY_CLASSES_ROOT\.py]
#="Python.File"
[HKEY_CLASSES_ROOT\.pyc]
#="Python.CompiledFile"
[HKEY_CLASSES_ROOT\.pyo]
#="Python.CompiledFile"
[HKEY_CLASSES_ROOT\.pyw]
#="Python.NoConFile"
[HKEY_CLASSES_ROOT\Python.File\Shell\Open\Command]
#="CMD /K \"\"C:\\Program Files (x86)\\Python\\Python.exe\" \"%1\" %*\""
[HKEY_CLASSES_ROOT\Python.NoConFile\Shell\open\command]
#="CMD /K \"\"C:\\Program Files (x86)\\Python\\Pythonw.exe\" \"%1\" %*\""
Could you try this as root:
$ ln -s python2.7 /usr/local/bin/python
Logout & login again as root:
$ python -V
It works for me, hoping the same to you.
Cheers,
I've downloaded python installer from http://www.python.org/ftp/python/3.1.2/ , this python-3.1.2.msi file, I need to execute some python files? How do I do that? For example in php I'd do php filename.php from console, I do however have python command line but I don't know how to execute those files.
So if I could set ENV variable to directly execute my file(s) if that is possible that would be great.
There is an option in the installer called "Register Extensions" to associate Python files with the interpreter, so double-clicking them or entering filename.py in the console should work.
Apart from that you might want to add C:\Python31 to your PATH variable (right-click on My Computer, choose Settings, choose the Advanced Tab - there you can access the system variables. Better do this as an admin.
If you type python in the Windows command line, what happens? Is the Python interpreter in your PATH yet?
If not, add the Python installation directory there (here's a good guide). Then just do python script.py just like with PHP.
you can just execute
python yourfile.py
Or if the python command don't work you have to give the absolute path to you python installation or add it to windows path