I've been struggling with this issue for a while, when I run python3 main.py my code runs, however when I try sudo python3 main.py it can't find the module that I've downloaded.
This hasn't been an issue until now, I want to run on boot, I have tried to edit the rc.local file, which needs superuser permission but of course it does not run without permission.
Also, when I install modules using the terminal, it doesn't seem to work at all, until I open thonny and download the modules that way, I can't see what i'm doing wrong.
Related
im on macbook old version El Capitan 10.11.6 and my python script is 147bytes just for auto shutdown program but when i try to boundle it pyinstaller filename.py it done almost everything and end up with (codesign failure). do someone know how to solve this?
Try the following command in your terminal, type: sudo codesign -f -s followed by your script name test.py Make sure you are in your script file directory by using cd path to your file folder.
After that, you can run pyinstaller test.py However, I am using macOS Monterey Version 12.6 and am not sure if it will work on your current version. In fact, I don't even know how that command makes it work, but it works for me. If your app is a windowed app, such as the Tkinter app, your system may prevent it from opening; in that case, use the following command to disable the security system sudo spctl --master-disable . then you will see a new option available in your macOS Settings under Security; down there it says Allow app from: App Store, App Store and identified developer; and at last, you will see a new option "Anywhere" which wasn't there before; check that, and your app will work perfectly. hope helped
Basically I am writing a script to reset a django webapp completely. In this script, I want to reset the database, and there is a command to do it from django extensions. Unfortunately, I haven't been able to run it programatically. It works fine when I run it via command line, but it just won't execute when I try programatically.
I have tried using os.system and subprocess.
I have also tried using management.call_command('reset_db'), but it keeps saying that there isn't a command called reset_db. I have checked to make sure the django_extensions is in my installed apps, so I have no idea why that isn't working.
Does anyone know how I could fix this? Thank you!
Also I am using python3, the most recent version of django I believe, and it is a MYSQL server that I am trying to delete.
I can't know without seeing your way of invocation directly, but my guess is the script's not running in the virtualenv. Here are some debug notes:
./manage.py --help | grep reset_db: Does this output anything?
./manage.py shell_plus
Then try:
from django.core.management import call_command
call_command('reset_db', '--help')
Anything then?
Also within ./manage.py shell_plus, try import django_extensions
Outside of the shell, try this: pip show django, pip django-extensions.
If it doesn't show those (e.g. WARNING: Package(s) not found: django-extension) and you think they're already installed, try this:
which python, which pip. Are you using venv, virtualenv, virtualenvwrapper, pipenvorpoetry`?
Try env | grep VIRT, do you see a VIRTUAL_ENV? If not you may need to make one.
When you run the script, you need to have your environmental variables set so you hook in to your site packages. In poetry we can do poetry run ./manage.py ourscript or poetry run ./ourscript.py without needing to be sourced. But we can also easily drop into virtualenv via poetry shell.
If you created an environment like virtualenv -ppython3.8 .venv, you can either do:
source .venv/bin/activate, ./myscript.py, rr you can try .venv/bin/python ./myscript.py
So I'm basically wanting to get a script to run on system boot. It's basically an SSH callback. I've tried a few ways that I've gotten to work in the past on other distributions, but having a little bit of difficulty here.
First thing I've tried was adding the /path/to/script.rb to /etc/rc.local. However, this file does not exist on the latest version of Kali Linux. I tried to create it and replicate my old Ubuntu rc.local file, but it didn't run on system startup.
Next thing I tried was creating an executable bash script in /etc/init.d/, following the update-rc.d script.sh defaults and making the file executable. Restarted and nothing. If I run the script manually, it works. I tried to redirect the output to a file in the tmp folder, but it doesn't appear that there are any errors from what I'm understanding.
Are there any other ways to get an auto run script started other than these two methods? Seem to be the most common way to get this working, but it's just not doing it for me.
Add script to
/etc/init.d
Run command:
chmod 755 /etc/init.d/script
Run command:
update-rc.d script enable
I have a script which I wrote in windows and is working fine, and I am now transferring to a CentOS.
The scripts transforms an excel file, to different forms of pivot_tables
I did the setup, and installed the pre-requisites.
Now when I try to run my scripts, they don't seem to work. It will prompt that the python component cannot be imported even though I just installed it.
Then I tried to run the script as sudo, then it worked like it worked on my windows environment. But my problem now is the file is totally unusable unless it is opened with sudo command.
Is there any way that I can run my scripts without using the sudo command?
This is the error I receive if I run the script without sudo:
Traceback (most recent call last):
File "step1.1_executeConsolidation.py", line 12, in <module>
from openpyxl import workbook
ImportError: cannot import name 'workbook'
(Workbook or workbook, I get the same results)
What I did to fix my issue is to use a virtualenv.
I installed the virtualenv, and create a folder to create an separate instance.
At this point, the folder for project is only accessible using sudo. So what I did was perform chown command to remove my folder from admin and transfer to my account.
Now whenever I activate my virtual env, and run my scripts and open the output file, I don't have to use sudo anymore.
I have a script that using splinter to take a screenshot of a certain page.
When I run this script on my home computer (ubuntu) it works perfectly fine (takes the screenshot). When I run it on the terminal (debiuan - sudo python) on my server it also works fine.
However, when I have it run the script on the server it does not seem to be able to save the picture.
Why is this?
I am inclined to say that python does not have write permissions but I run the python script with sudo and I chmod 777 the directory, but it still is not able to save the picture.
Is there any other way I have to give python permissions or is this not a permission issue?
The line where splinter is taking a picture is
browser.driver.save_screenshot('picture.png')