I am running an apple script that will run a python file upon the mac waking up from sleep. The applescript works and runs the python file. The problem is that if I try and run a python file that would uses modules then the file wont run. The error i get is saying that the computer cannot find the specific module.
in development i use a pipenv to install the modules.
If i could some how run a pipenv install required-modules either from the apple script or the python file i think this would solve my problem.
There is a thread on here that mentions trying to run AppleScript => bash => python file. However I have looked into it but my lack of knowledge is not enough to figure it out.
So my question is can a 'pipenv install required-modules' be run from an apple script or a python file?
I am running the python file from the following apple script:
set desktop_folder to "$HOME/Desktop"
do shell script "python " & desktop_folder & "/foobar/main.py"
Related
I have just started working on my new pc and just to get a feel for it I wanted first to start working on python files, so I started first by just wanting to run WSL on windows and it installed correctly but when I want to run any python using the run python file on the top right on VS code, this is what gets executed $ C:/Users/jaffe/AppData/Local/Microsoft/WindowsApps/python3.10.exe f:/Projects/hello.py
And this is the error: -bash: C:/Users/jaffe/AppData/Local/Microsoft/WindowsApps/python3.10.exe: No such file or directory
I have no idea what's causing it but when I run the file using 'Shift + Enter' which is: Python: Run Selection/Line in Python Terminal it seems to run the single line correctly but it gives me this error instead:
print("Hello, world")
-bash: syntax error near unexpected token `"Hello, world"'
but when I run it using python3 hello.py, it works perfectly fine?! I'm so lost as to why this is happening and how could I fix it.
Might be relevant: I'm using windows 10, installed python 3.10.2 from windows store, all of that is in VS code and the python code is one line: print("Hello, world") and I changed the permissions of Local/Microsoft/WindowsApps so it's now accessible by all users to view/read/edit/run, made sure that python3.10.exe exists(on the WindowsApps and it works perfectly) and reinstalled it many times, tired python3.9, and tried to install python from the website instead of the windows store and still the same, manually added python to PATH and tried .venv and didn't work. when I launch python3.10.exe outside vs code it seems to run perfectly, I have worked with python before and it used to work fine now I don't know what's wrong.
I have seen other questions of the same problem I'm having here but none of them solve the problem.
No such file or directory C:/Users/...
For wsl, the Windows filesystem is accessible, but it has a different path. It is mounted under the /mnt folder. So you would find your python .exe under /mnt/c/Users/jaffe/AppData/Local/Microsoft/WindowsApps/python3.10.exe. This said, the executable file is meant to work on Windows, and it doesn't really makes sense to use it on Linux when you could run python within your wsl distro.
python3 works perfectly fine
This is because most Linux distributions come with python3 pre-installed, so you can use it already. To see where it is located, you can run the command which python3, or python3 --version to check its version.
If you want to change version, you may consider download it from you package manager, apt.
I also suggest to install python3-pip if you don't have it already to get the pip package manager for python.
In my case when I ran into this.. I discovered pyenv. This allows you to download more than one version of python. You can then go into a specific directory, such as your python project and issue a python local 3.10.0 (for example). Here's a link on how to install it as well as poetry which is a virtual environment manager that is become very popular. You can also create an alias for python that works off of this. I add this command to my alias file and source it from my .bashrc. alias python='pyenv exec python3'
I am trying to work on a lab machine using Python scripts that run fine on my local machine. The scripts were written for Python 2.7, and use the AARDVARK device library as an imported module.
The script runs on Windows' command shell, but fail to run on the installed Cygwin bash shell. The PYTHONPATH variable is defined correctly and similar to my local machine. When running, it complains that it cannot fin the AARDVARK module. So, following this question, I added the sys.path.append('/cygdrive/c/aardvark') command to my script.
Now, when I try running it, I get a pop-up message window saying Unable to bind Python API. API supports Python 2.3,2.4,2.5,2.6,2.7. Running python --version on the bash command line, I get 2.6.7.
What is this error message and how to eliminate it?
How can I make the script run and use the aardvark module?
I'm working on a deployment process for work and have run into a bit of a snag. Its more of a quality of life thing than anything else. I've been following Hynek Schlawack's excellent guide and have gotten pretty far. The long and short of what I'm trying to do is install a python application along with a deployment of the python version I'm currently using. I'm using fpm to build an RPM that will then be sent and installed to site.
As part of my deployment, I'd like to run some post-install scripts. Which I can specify in fpm using the "--post-install {SCRIPT_NAME}" This works all well and good when the script is an actual linux script. However, I'd really like to run a python script as my post-install. I can specify an executable python script, but it fails because I believe it is trying to execute the script as: bash my_python_script.py
Does anyone know if there is a way to execute a python script post-install of an RPM?
Thanks in advance!
In the spec file you can specify what interpreter the %post script is for by using the -p parameter, e.g. %post -p /usr/bin/perl .
I'm trying to use Pypy to make my code run faster, but I don't know what to do with the zip file I downloaded from the site (I tried to read the directions but it moves too fast and I don't know what's going on). I was wondering if anyone had simple step by step instructions on how to install and use Pypy. Also, Im using Wing on Windows
Unzip the zip file to a suitable location, e.g. C:\pypy then run pypy.exe from the folder to which you unzipped. There is no installation for pypy. Similarly to uninstall just delete the folder.
Running C:\pypy\pypy.exe gives you an interactive prompt, just like the one you get for running any other version of Python except it uses four chevrons >>>>.
To run a script with pypy you can explicitly name the interpreter:
C:\pypy\pypy.exe script.py
Or, if you have Python 3.3 installed on the same system, you can use the Windows Python launcher. Edit the ini file (%USERPROFILE%\AppData\Local\py.ini) with %USERPROFILE% replaced by your home folder name to contain:
[commands]
pypy=c:\pypy\pypy.exe
Then you can simply put a hashbang line at the start of any script and it will automatically run pypy when you run the script from a command line e.g. script.py, or when you click on its icon:
#!pypy
import sys
print(sys.version)
or use #!python27 to make a script run with Python 2.7, or #!python33 to make it run with Python 3.3.
Hello gyus i have started python and i want to know how can i excecute python file without using terminal.Just like the most games using (exe) file extension but for py files.I have tried py2exe but it doesn't show anything on the screen. I tried to make excecutable the py file with no luck. Please tell me how to excecute the and if there is an option whithout using a specific program for that.
My system is : Windows 7 / Ubuntu 12.04
Here, have a look in my blog, It explains how ca you do it in Ubuntu.
http://insidepython.wordpress.com/2012/08/04/hello-world-or-how-or-say-ni/
but basically:
Add this line to the beginning of your script
#!<location of your python interpreter>
To find out where your python interpreter is installed:
$ sudo find / -name "python"
After executing the previous, you should get the location of your python interpreter, then you need to set the environment variable, in my case python executable is located in /usr/bin/python
$ export PATH="$PATH:/usr/bin/python"
Then you need to set the file attributes to executable, you can look more into file attributes in Unix/Linux here http://en.wikipedia.org/wiki/Chmod
$ chmod +x shrubbery.py
And finally to execute your application
$ ./shrubbery.py
For Windows, there's also a python script called GUI2Exe that I have used in the past to create distributable versions of python scripts as apps. It's available at
http://code.google.com/p/gui2exe/ and is, in my opinion, very simple to use. Tutorials and whatnot are easy to find on Google.
It uses py2exe (or any other Python compiler library) to put together the script, but it doesn't require any syntactically annoying setup.py file.