I have python.exe installed on my machine (several times) but no python.bat. I'm trying to build Chromium Embedded Frameworks and the master batch file says
#echo off
python.bat tools\gclient_hook.py
but python.bat not on my machine giving error 'python.bat' is not recognized as an internal or external command,operable program or batch file.
Is there a python scripting edition or something?
UPDATE: SO User R-nar was correct, needed stripping off .bat
This is not my code but part of Chromium Embedded Frameworks.
cef_create_projects.bat
Ok, so after fixing I am running into Python 2 errors. It looks like python.bat may have been an indirection mechanism to keep the Python 2 scripts working.
You have to use python.bat from depot_tools, see step 2 here:
https://bitbucket.org/chromiumembedded/cef/wiki/MasterBuildQuickStart#markdown-header-windows-setup
Download depot_tools.zip and extract to "c:\code\depot_tools". Do not use drag-n-drop or copy-n-paste extract from Explorer, this will
not extract the hidden ".git" folder which is necessary for
depot_tools to auto-update itself. You can use "Extract all..." from
the context menu though. 7-zip is also a good tool for this.
Check if have the the directory of python.bat in your environment path variable, otherwise python.bat must me in the current working directory.
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.
I've created a project in Pycharm that is composed by 3 py scripts and requires a json file with authentication parameter to read files coming from google drive and finally a file to manipulate data in a sqlite table create on the fly.
That works super good in my computer and the server (windows server 2016 standard edition). I need to execute this program(script) whole days so I've tried with the script.py using cmdExec in SQL and Windows scheduler manager and it doesnt work. otherwise if manually in the server I perform double click that runs.
I realized that when I run the script manually the execution is
C:\path of folder where is the script> C:\whole path again\script.py
Otherwise from windows scheduler is always:
C:\windows\system32> C:\whole path again\script.py
How can I force to fix this path or probably if I can create a .exe of my project in pycharm that could work? But I've not found too much info about how follow this process.
If you want to create an exe you can use cx_Freeze or py2exe.
However, you could also try an other way (such as .bat file).
I think "pyinstaller" is the best choice. it can package a python program to an *.exe file. so you can execute this program om windows platform. And you don't need to install python on windows. office website is "http://www.pyinstaller.org/". it is easy to use.
note:pyinstaller don't support python3.6
hope to help you.
Hi guys finally after a research within our library contributions I found the follow link where another person shared the experience to create a bat file.
Finally following this post from another contributor I could figured out my issue and my bat scripts looks like:
#echo off
py -u "path\ReadFile.py"
echo %ERRORLEVEL%
Thanks everyone
i've installed py 2.7 (64bit) on my PC with Win7 (64bit) without problem but I'm not able to run *.py scripts via DOS shell without declare python full path.
Let me better explain :
If I type D:\ myscript.py it doesn't work. The script is open with wordpad
If I type D:\ C:\Python27 myscript.py it works and run correctly
I try to change the default application software for *.py file via Win7 GUI ( control pannel etc etc) but without success.
Python is not present in the list of available sw and in any case also with the manual set I'm not able to associate python.exe at *.py files.
I've checked in my environment variables but I've not found problem (python path is declared in Path = C:\Python27\;C:\Python27\Scripts).
I've tried also to modify HKEY_CLASSES_ROOT->Applications->python.exe->shell->open->command :
old register value "C:\Python27\python.exe" "%1"
new register value "C:\Python27\python.exe" "%1" %*
without success.
Any suggestion?
Thanks
Here is another check to make, which helped me figure out what was going on.
I switched from the 32bit Anaconda to the 64bit version. I deinstalled, downloaded then reinstalled, but several things didn't get cleaned up properly (quick launch stuff, and some registry keys). The problem on my side was that the default installation path changed, from C:\Anaconda to C:\Anaconda2.
I first tried the assoc and ftype tricks, everything was fine there. However, the HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command registry key was pointing to the old Anaconda path. As soon as I fixed this, python.exe showed up when I tried associating with "Open with" and everything went back to normal.
I also added the %* at the end in the registry key.
You could try to use the ASSOCIATE command in CMD:
ASSOCIATE .py C:\PathTo\python.exe
More information at http://ss64.com/nt/associate.html
#slv 's answer is good and helped me a bit with solving this problem. Anyhow, since I had previous installations of Python before this error occured for me, I might have to add something to this. One of the main problems hereby was that the directory of my python-installation changed.
So, I opened regedit.exe and followed these to steps:
I searched the entire registry for .py, .pyw, .pyx and .pyc (hopefully I did not forget to mention any here). Then, I radically deleted all occurrences I could find.
I searched the entire registry for my old python-installation-path (e.g. C:\Users\Desktop\Anaconda3). Then I replaced this path with my new installation path (e.g. C:\Users\Desktop\Miniconda3). Thereby, I also came across and replaced HKEY_CLASSES_ROOT\Applications\python.exe\shell\open\command which #slv mentioned.
Afterwards, it was possible again to connect a .py-file from the Open with...-menu with my python.exe.
The *.py file is a source code file. If you set up your system environment correctly, you need to run python myscript.py
the following answer is related to your question
Making Python scripts run on Windows without specifying ".py" extension
Do you know that when you change the default application of a file, you are able to browse for the application?
You can click on the "browse" button (as shown in the red rectangle), then choose C:\Python27\python.exe.
Also remember to click on the "Always use this program to open this program" checkbox, which is shown in the green rectangle, so that win7 knows how to open this file the next time you ask it to open *.py file.
Then I believe you'll be able to run myScript.py simply by typing "myScript.py" in the correct dirctory in DOS shell.
After doing all the above steps, be sure to reopen a new command shell.
Yes, I read some of those .pyc questions, but still nothing.
I need to save a project to a CD and preferably I'd like to be able to run it right from there. Should I put the .pyc files in there or not?
No,
byte-code is not version compatible
Yes
the project is supposed to run with the same python version
.py files won't be changed any more in that release
it might be load faster
if smth doesn't suit, python will (need to) create new .pycs somewhere anyway
The latter one: Python will handle that and use a temp directory, won't it?
Answer : No Need to Include
You want to Compile & Run Means :-
Your question says, you are going to compile your python source code in another machine. When you compile your code, the ".pyc" file will be created. So, it is not necessary to include the ".pyc" file with your cd. If you put means, no problem, when you compile your source code in another machine, it will replace the ".pyc" file with the newly created ".pyc" file.
You want to Only Run Means:-
But, if you want to run without compile means, you should convert your program into executable. Executable file may be for windows or linux.
For Linux, to create executable file : Use "CDE" package.
Link: http://www.pgbovine.net/cde.html
For Windows, to create executable file : Use "Py2Exe" package
Link : http://www.py2exe.org/index.cgi/WorkingWithVariousPackagesAndModules
I hope this is the answer you want.
PYC is python bytecode making the original code run faster. You can omit it, since your code will still be able to run.
However if you need to run your code on different machines, probably without any python distribution. Take a look at
http://www.py2exe.org/ which is for windows only
http://www.pyinstaller.org/ which is for most systems
I personally worked with py2exe, it is simple to use. Although it makes fairly huge package, since it add all python packages required to run the original python script.
Hope this is helpful for You.
I made a simple hello program using Sublime Text. Run it using windows powershell but everytime I am getting error like :
C:\Python27\python.exe: can't find '__main__' module in 'X'
X is the name of folder. I have Python 2.7.4 Installed. How to fix it?
Maybe there's something wrong with your C:\Python27\python.exe.
See if there are two python under the folder C:\Python27:
python.exe
python2.7.exe.
If so, chose the python2.7.exe
Also possible if your module X is in anaconda or something similar, then you should adjust your Sublime environment to include anaconda (or whatever you're using).
Tools -> Build System -> New Build System
I know nothing about Python, other than running other people's Python apps on Windows occasionally. I see that this is an old thread, but still ran into this just now--the app threw this error and wouldn't run at all unless I included the '.py' extension on the command line.
This error can be caused by file corruption -- check that your module 'X' was copied correctly to the destination folder -- try opening it in an editor and make sure it looks ok. You will get this same error if you try to run Python on a file which is not a text file or a precompiled python module.
This problem is the same what I get last night, if you are using PyCharm to code Python, you can re-check the existing configuration, make sure in the working directory section it is filled in, and in the script path section, it is the same as the file location and file name.
Actually this is a problem where you have to write down the correct storage place.