On a Windows machine, where I have no admin rights, I've created a python script which loads a module that is only available in Spyder development environment. To run it, I have to open Spyder, select the script and the working directory, before actually running the program.
I'd like to automate those steps. The ideal way would be to run the script from a console (in the correct directory), loading the python modules available in spyder.
Something like:
spyder.exe myPythonScript.py
Any idea about how to do it?
Related
I am currently using VS Code on a server (through SSH). Everything works fine, and I installed Python packages and work with Python notebooks.
Now, I want to login to the server (not a problem) and run the Python code I created on VSCode, rather than executing it remotely.
My main issue is that I am not sure how to activate the Python environment (if there is one) that VSCode server's run so that the code can execute.
Is that possible?
I see I have a .vscode directory in my home directory, and there are package installation there.
After connecting vscode remotely, you can use it as a regular vscode, which is no different from running Python files locally:
install python
install pylance extension
choose correct interpreter
edit your code and run the python file.
I had created with tkinter an application.
this application (python.py) contains a button, by clicking on the button it calls scripts (scripts that I have already created before) and executes them.
I was able to convert python.py to python.exe with pyinstaller (pyinstaller --onefile python.py)
after this step I put my python.exe and pycache and all the scripts (with extensions py) that I should use on my application in a single folder and open the folder in NSIS … so you can send it to another user who doesn't have python
On other pc : the application opens but as soon as I click on the button to have the execution of the scripts I have an error
python was not found; run without arguments to install from the Microsoft store, or disable this shortcut from settings > Manage App Execution Aliases.
I fix it with disable app python on manage app execution aliases. (I don’t know if it correct), but I tried to run it again and I have this error
python’ is not recognized as an internal or external command, operable program or batch file.
yet everything works fine on my pc
knowing that I work on windows
maybe i forgot a step?
Python interpreter is not installed on the target PC. Bundle your executable with all dependency libraries necessary to run your application on any windows PC. Also note that your windows version matters too.
I have a script that i run every day and want to make a schedule for it, i have already tried a batch file with:
start C:\Users\name\Miniconda3\python.exe C:\script.py
And im able to run some basic python commands in it, the problem is that my actual script uses some libraries that were installed with Anaconda, and im unable to use them in the script since Anaconda will not load.
Im working on windows and can't find a way to start Anaconda and run my script there automatically every day.
I would be a bit careful in calling python directly through environment as one never knows if the internals for activate function has changed.
I'm just using basic bat-script to help me out.
SET log_file=%cd%\logfile.txt
call C:\Anaconda3\Scripts\activate.bat
cd \script_directory
python script.py arg1 arg2 > %log_file%
This script saves the log-file wherever the bat is run from, calls the right environment through activate (in this case the standard) and directs all the stdout into log-file for further investigation.
Then just point your Windows Task Scheduler to the script and set the home directory where you want the log-file to appear.
I'd recommend creating an Anaconda environment with the packages you need, then using the python from that environment to run your script. Read about Anaconda environments here
For example...
Say you create an environment called cristians_env
conda create --name cristians_env
and you install the packages you need
conda install pandas
Then, all you need to do is this from your batch script (assuming you use Anaconda 2)
start C:\Users\name\Anaconda2\envs\cristians_env\bin\python C:\script.py
and voila! You're using your anaconda environment from your batch script!
I had a similar problem a few days ago.
What I discovered is that anaconda prompt is nothing but your usual cmd prompt after running an 'activate.bat' script which is located in the anaconda 'Scripts' folder.
So to run your python scripts in anaconda all you need to do is write 2 lines in a batch file. (Open notepad and write the lines mentioned below. Save the file with .bat extension)
call C:\....path to anaconda3\Scripts\activate.bat
call python C:\path to your script\Script.py
Then you schedule this batch file to run as you wish and it will run without problems.
Found a solution, i copied the "activate.bat" file in "C:\Users\yo\Miniconda3\Scripts" and renamed it as schedule.bat and added my script (copy pasted it) on the end of the file.
Then i can schedule a task on windows that executes schedule.bat everyday
I have a script that I wrote in Python. It uses some libraries such as Twython that allows me to post pictures and text to twitter. Now I am trying to make my own photo-booth that runs on Windows. I wish to run the script on the windows computer and I do not wish to install Python on the Windows machine.
I have tried to make exectuables but they do not work (I think because I have inputs that need run after the script (python script.py Message filepath). I thought there was a way to include everything of a normal Python install in the folder you run your script from and it will allow me run it cross platform.
Edit: My question is how can I package python up to run with out installing it preferably from a folder on the desktop.
I downloaded this tool to migrate MySQL to PostgreSQL: https://github.com/philipsoutham/py-mysql2pgsql
Python interactive code works properly so the python path is set in the right way.
When I type "py-mysql2pgsql" being in the directory: C:\Users\me, the downloaded tool doesn't run but ask me to choose the program to open that file. The same situation when I'm in C:\Users\me\py-mysql2pgsql
How can I run this tool properly?
Windows does not understand shebang lines in scripts (#!/usr/bin/env python) like Linux and Unix variants do. So Windows does not understand that this is a python script, you need to execute python yourself.
If python executable is in your path, you should be able to run:
python py-mysql2pgsql
If it is not in your path, you should be able to run:
path_to_python\python py-mysql2pgsql (on my machine C:\Python27\python)
Note that this applies to any python script on Windows, not just this tool.