I am simply testing how to call external .py files from one .py file.
I have 2 .py files, both in the same directory. Here is the code for the main one (runext.py suppose to call ext.py):
import subprocess
subprocess.call("/Users/training/PycharmProjects/MarcouFirstProject/ext.py")
ext.py is just print("hey this actually worked")
However, every time I run runext.py, I get this error message:
Traceback (most recent call last):
File "/Users/training/PycharmProjects/MarcouFirstProject/runext.py", line 2, in <module>
subprocess.call("/Users/training/PycharmProjects/MarcouFirstProject/ext.py")
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 557, in call
with Popen(*popenargs, **kwargs) as p:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 947, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1551, in _execute_child
raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied
I don't know why it denies permission. This is on a school computer (I'm in a programming class) if that helps.
Thanks.
You don't have the permissions to execute the file /Users/training/PycharmProjects/MarcouFirstProject/ext.py
You can add the permission +x by using chmod:
chmod +x /Users/training/PycharmProjects/MarcouFirstProject/ext.py
Or, you can use python explicitly:
import subprocess
subprocess.call("python /Users/training/PycharmProjects/MarcouFirstProject/ext.py")
Related
I'm trying to run a python flet script on repl.it. Here's what I did:
created a new repl, for a python script; repl.it creates a main.py file
from the Packages tool I imported flet
I wrote this code into main.py:
import flet as ft
def main(page:ft.Page):
page.add(ft.Text("Hello World"))
page.update()
ft.app(target=main)
And I clicked the Run button. I got this error:
Traceback (most recent call last):
File "main.py", line 8, in <module>
ft.app(target=main)
File "/home/runner/test/venv/lib/python3.10/site-packages/flet/flet.py", line 102, in app
conn = _connect_internal(
File "/home/runner/test/venv/lib/python3.10/site-packages/flet/flet.py", line 192, in _connect_internal
port = _start_flet_server(
File "/home/runner/test/venv/lib/python3.10/site-packages/flet/flet.py", line 361, in _start_flet_server
subprocess.Popen(
File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/subprocess.py", line 971, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/nix/store/hd4cc9rh83j291r5539hkf6qd8lgiikb-python3-3.10.8/lib/python3.10/subprocess.py", line 1847, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
PermissionError: [Errno 13] Permission denied: '/home/runner/test/venv/lib/python3.10/site-packages/flet/bin/fletd'
I've gotten this same Permission denied error with every flet script I've tried. (Non flet scripts don't have errors.)
I wrote a python program that upload an excel file to SAS dataset on server. I tested it on my laptop and a few other people's laptop it worked fine. But when I was testing that on one of my colleague's PC I got the following message:
Traceback (most recent call last):
File "call_sas_program.py", line 56, in
subprocess.call(["sasgsub", "-gridsubmitpgm", upload_excel.sas])
File "/opt/packages/anaconda/lib/python2.7/subprocess.py", line 523, in call
return Popen(*popenargs, **kwargs).wait()
File "/opt/packages/anaconda/lib/python2.7/subprocess.py", line 711, in init errread, errwrite)
File "/opt/packages/anaconda/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
OSError: [Errno 13] Permission denied
I used python's "subprocess". It looks like a permission issue with the subprocess, but I suspect it's the permission to create SAS table. Has anyone run into this problem before? And how to solve it?
Thanks!
Im learning Python.
Getting below exception while trying to clone a repos
Traceback (most recent call last):
File "C:\Users\Selvakumar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\git\cmd.py", line 622, in execute
**subprocess_kwargs
File "C:\Users\Selvakumar\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 969, in __init__
restore_signals, start_new_session)
File "C:\Users\Selvakumar\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 1249, in _execute_child
startupinfo)
PermissionError: [WinError 5] Access is denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "config_console.py", line 2185, in <module>
command_line = ConfigCommandLine()
File "config_console.py", line 87, in __init__
g.clone('git#github.com:Modria/Ecomm_GM.git')
File "C:\Users\Selvakumar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\git\cmd.py", line 463, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "C:\Users\Selvakumar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\git\cmd.py", line 905, in _call_process
return self.execute(make_call(), **_kwargs)
File "C:\Users\Selvakumar\AppData\Local\Programs\Python\Python36-32\lib\site-packages\git\cmd.py", line 625, in execute
raise GitCommandNotFound(str(err))
git.exc.GitCommandNotFound: [WinError 5] Access is denied
GitPython is installed. ssh keys are available in C:\Users\Selvakumar.ssh and its working when I clone from git bash. But the same not working from python. Please note that ssh keys are generated with no password. Please help me to resolve it
The OP confirms it is a PATH/variable issue
Does your PATH references git binary?
Yes, that was the mistake I did. I missed to git.exe in GIT_PYTHON_GIT_EXECUTABLE path variable.
Given like this as C:\Program Files (x86)\Git\bin\git.exe and it works.
You can see that variable introduced here in GitPython 26
If set, it should contain the full path to the git executable, e.g. c:\Program Files (x86)\Git\bin\git.exe on windows or /usr/bin/git on linux.
The GitPyhton README states:
GitPython needs the git executable to be installed on the system and available in your PATH for most operations.
If it is not in your PATH, you can help GitPython find it by setting the GIT_PYTHON_GIT_EXECUTABLE=<path/to/git> environment variable.
seems like an authority error, be sure to run your script as an administrator
I have a python script that will read the temperature of from a probe on the GPIO pins of a Raspberry-Pi, and will append that temperature to a log file. Running the script form terminal with sudo permissions works fine:
sudo python /home/pi/temp.py
I've attempted to run the script every 15 minutes from sudo's crontab file with the line:
*/15 * * * * python /home/pi/temp.py
This fails, with the output being
Traceback (most recent call last):
File "/home/pi/temp.py", line 8, in <module>
subprocess.call(['modprobe', 'w1-gpio'])
File "/usr/lib/python2.7/subprocess.py", line 493, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
I know the issue is with the modprobe subprocess call, but I can't identify what exactly. In my script, I have the following code related to the issue:
import subprocess
subprocess.call(['modprobe', 'w1-gpio'])
subprocess.call(['modprobe', 'w1-therm'])
This is because cron has its own PATH variable and doesn't use the same path that you do.
For that reason, it would be advisable to call any programs that you use (especially through python's subprocess) with an absolute path to the executable
You could do which modprobe on the commandline to find where modprobe lives (probably in /bin/), and then change your call in subprocess.py to subprocess.call(['/bin/modprobe', 'w1-gpio'])
i installed python-nmap-0.1.4.tar.gz in pyhton27 in window. When i ran this http://codepad.org/vTu1Uw7I script, i got a few error. What those error mean?. Are those error happened because i used python-nmap-0.1.4.tar.gz in windows?.
Here is the error
Traceback (most recent call last):
File "C:/Python27/Lib/site-packages/nmap/run-nmap.py", line 3, in <module>
nm = nmap.PortScanner() # instantiate nmap.PortScanner object
File "C:/Python27/Lib/site-packages/nmap\nmap.py", line 118, in __init__
p = subprocess.Popen(['nmap', '-V'], bufsize=10000, stdout=subprocess.PIPE)
File "C:\Python27\lib\subprocess.py", line 711, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 948, in _execute_child
startupinfo)
WindowsError: [Error 2] The system cannot find the file specified
Here is the subprocess.py script
http://codepad.org/SpbV8muR
Seems that python-nmap is meant to be run on Linux… but you can still try to make it work on Windows. The problem is that it is trying to call nmap but the binary is not found in PATH.
Add the directory with nmap executable to you PATH variable. Here is a HOWTO.