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
Related
What is the simplest tool to convert a python script into an executable file?
I made a python script and requirements.txt which contains necessary packages for a virtual environment with python3.6. I gave them to my client so that he can create a virtual environment and execute the file by executing the three lines below in the console.
source activate
python __main__.py
deactivate
Basically he needs to run it once a day, so that my python script scrapes a stock index data release at the end of each day and does some data transformation and saves the data in a desired directory as excel files.
However my client told me "even the three lines are difficult for people who are not familiar with CUI. Can you make it like a clickable icon?"
Is there any tool that can easily package my python script and required packages as an executable file or icon? It doesn't have to be cool. A simple and primitive tool would serve our needs. My client has Windows 10 Pro 64bit but it has to be something that I can develop in my My work environment which is Mac OS Catalina.
Thank you!
Yes, it is possible following library's help with this.
PyInstaller can be used, under Mac OS X, Windows, Linux,...
For an example i would read this medium post, it should contain everything to get you started.
py2exe can be used if you only want an executable for the Windows platform.
I am new to Python. Please excuse me if my question seems stupid. I have spent a lot of time before posting this.
When I searched for shipping python interpreter with the applications, I found solutions including installing separate applications, using third party modules, etc...
I was thinking of more direct approach: I first install python interpreter on my machine (windows). Then I ship the installed python interpreter (copy and paste the folder) with the pyc file of my application. And finally I create a simple batch program that executes the interpreter and running the pyc file. In this case, the user can simply run the application by simply running the batch program. I have tried it and it worked.
Although this solution seems the most obvious and the easiest one, I am in a doubt about it because I cannot find any one mentioning it. Is there anything wrong with my solution? I usually create desktop applications for windows.
Thanks in advance.
Make a virtual environment for you application and then run run the command python filename.py --onefile --windowed while still being in the virtual env. activated,
I'm new to Linux. I recently downloaded Bash on Ubuntu on Windows 10 (after the Anniversary edition update to Windows 10). Since this update is relatively new, there is not much online regarding troubleshooting. There are two things I need help on:
(1) When I go to the home folder, which seems to be "C:\Users\user\AppData\Local\lxss\home\user" and I add a new folder through Windows, this folder does not show up in Linux with the "ls" command. But when I add a directory using "mkdir" in Linux, the "ls" command shows this folder. Why is it behaving like this? Am I limited to creating folders through "mkdir" when working in this folder?
(2) I have a Python script sitting in that same folder that I'm trying to run and again it is not being found by Linux or the Python interpreter started in Bash on Ubuntu on Windows. I have Python 3 installed (Anaconda) and I'm able to type commands directly in the Python interpreter and it's working. However, I would like to run scripts in files.
Please let me know if more information is needed. Thanks.
The reason why ls is not showing anything is that it shows the Linux directory structure. Try setting it to the Windows directory, in this example the c drive:
cd /mnt/c
Does ls show a folder structure now?
Looks like you are having permissions issues.
To see everything on your home folder try
ls -al
to change permissions check out the chmod command
How about using Python for Windows and NotePad++ to edit and run your Python scripts?
https://www.python.org/ftp/python/3.5.2/python-3.5.2-amd64.exe
You can setup NotePad++ as described here.
How to Execute a Python File in Notepad ++?
(I ended up using Cloud9 https://c9.io/ for Python. It is independent of your local environment or OS)
I need some help with converting a python windows service using py2exe.
Let me explain the problem. I have a python service, which works, no problems here. I used py2exe to turn it into an executable file. I tested it by replacing the python version of the service with this one and it works with no problems too.
But when I move the exe version of the service to another computer, it will register with the service manager but won't start with the error: "The system cannot find the file specified". The missing file is one of the modules I've written.
I played with this a bit and went back to the machine where I used py2exe and where the exe version of the service works. I removed everything python related, everything py2exe created but the "dist" folder, everything I could think of that was related with the python version of the service. The exe version still worked (altho I removed, amongst others, the very files that were supposedly missing on the other machine).
Tried a bunch of different things but cant get the exe version to work. If any of you guys have any ideas, I'd really appreciate it.
P.S: I do have the c++ runtime installed on the target machine. You can't register the service without it and as I said, I can register it, it just won't run.
Even if you converted the .py script to an exe, the service still uses the python interpreter to run the service code itself. if you open "Services" and look at the service properties you should see something like -
Path to executable:
"C:\Python27\lib\site-packages\win32\PythonService.exe"
i'm guessing the other computer doesnt have python installed on it.
if you want to be able to run that service on a machine without installing python you need to do something like This
,or you can also do it using cx_freeze
http://www.py2exe.org/index.cgi/py2exeAndWindowsServices
There are some notes in there about modules conflicting with windows system dlls. He had a problem because he had a module called version and import version caused the app to error out.
You can try importing win32traceutil as the first thing in your service. This should allow you to run the win32traceutil console app to display any stdout/stderr output from the service.
I'm soon to launch a beta app and this have the option to create custom integration scripts on Python.
The app will target Mac OS X and Windows, and my problem is with Windows where Python normally is not present.
My actual aproach is silently run the Python 2.6 install. However I face the problem that is not activated by default and the path is not set when use the command line options. And I fear that if Python is installed before and I upgrade to a new version this could break something else...
So, I wonder how this can be done cleanly. Is it OK if I copy the whole Python 2.6 directory, and put it in a sub-directory of my app and install everything there? Or with virtualenv is posible run diferents versions of Python (if Python is already installed in the machine?).
I also play before embedding Python with a DLL, and found it easy but I lost the ability to debug, so I switch to command-line plug-ins.
I execute the plug-ins from command line and read the STDOUT and STDERR output. The app is made with Delphi/Lazarus. I install others modules like JSON and RPC clients, Win32com, ORM, etc. I create the installer with bitrock.
UPDATE: The end-users are small business owners, and the Python scripts are made by developers. I want to avoid any additional step in the deployment, so I want a fully integrated setup.
Copy a Portable Python folder out of your installer, into the same folder as your Delphi/Lazarus app. Set all paths appropriately for that.
You might try using py2exe. It creates a .exe file with Python already included!
Integrate the python interpreter into your Delphi app with P4D. These components actually work, and in both directions too (Delphi classes exposed to Python as binary extensions, and Python interpreter inside Delphi). I also saw a patch for Lazarus compatibility on the Google Code "issues" page, but it seems there might be some unresolved issues there.
I think there's no problem combining .EXE packaging with a tool like PyInstaller or py2exe and Python-written plugins. The created .EXE can easily detect where it's installed and the code inside can then simply import files from some pre-determined plugin directory. Don't forget that once you package a Python script into an executable, it also packages the Python interpreter inside, so there you have it - a full Python environment customized with your own code.