Cron fails with the message Superset: command not found - python

I've installed Superset following the installation guide in the apache superset web page, for Python 3.7.
Even though I can manually start the server, when I'm trying to script the startup steps and cron them, it fails.
The output of the execution is the following:
superset: command not found
I've read the replies of this topic but nothing applies to this case.
I'm not using virtualenv for the installation.
These are the output of the which commands:
ec2-user#Superset-STAGE /var/spool/mail$which python3
/usr/bin/python3
ec2-user#Superset-STAGE /var/spool/mail$which superset
~/.local/bin/superset
ec2-user#Superset-STAGE /var/spool/mail$sudo superset
sudo: superset: command not found
Would you please guide me on how to have my script working without failure? Script looks like below.
superset init
wait
superset runserver -d

Cron runs as root, which means its home directory is /root rather than /home/ec2-user as you expect. This means that it will not be able to find /home/ec2-user/.local/bin/superset because it neither looks for executables in a ~/.local/bin/superset nor is it logged in as a user that has such a directory. A quick fix here is to use the full path, but I would recommend moving the executable to a more appropriate directory such as /usr/local/bin and then adding it to the PATH variable in /etc/profile

Related

I can't open manage.py

On the command prompt, (Windows 10) I created a virtual environment, I then created a new project, I installed django in the virtual environment using pip. Then decided to run the command
python manage.py runserver
To run djangos web server,
This returned with
"...can't open file 'manage.py': [Errno 2] No such file or directory"
I did see a similar question to this on this platform but it seems to only apply to those using linux. Where answers specify to use the ls command, which is not applicable on Windows command prompt. I have tried this multiple times but i just can't open
manage.py
When running a command on the command prompt, it is necessary to provide the correct path to the file.
Let's pretend you have your django files stored in a folder with the following path:
C:\my_stuff\subfolder\django_project >
Presume that when you run the dir command (the Windows analog to the ls command you mention in your question) it might show something like this:
C:\my_stuff\subfolder\django_project > dir
blog
db.sqlite3
manage.py
mysite
If you were to then run your command:
C:\my_stuff\subfolder\django_project > python manage.py runserver
Everything should work fine. But if you are in a different directory, you will get the error you describe. For example, this will fail.
C:\my_stuff\subfolder > python manage.py runserver
If, for some reason, your Windows command prompt does not show you which directory you are in, you can run the cd command to confirm where you are.
An alternate method is to point the python interpreter to the location of the manage.py script, by providing the path:
C:\my_stuff\subfolder > python django_project\manage.py runserver
But this sometimes introduces subtle problems, because scripts like manage.py might be written with the expectation that they will be run from the directory they are stored in. Your mileage may vary.

bash ./ command stopped working with pyvenv?

I'm using python 3 and have many virtual envs using pyvenv on mac osx 10.9.3. In all of them the command ./ runs my python code. In one of my envs the command has stopped working and I can not find anything about how to get it to begin working again.
EDIT: I get permission denied when typing out the whole file instead of tab (i.e. ./manage.py), and when I add sudo it works, but all the other venvs don't require sudo.
I'm searching through pyvenv docs and searching through various bash links but can't get it to restore or know where that shortcut comes from.
When I type python [file] everything works as expected, but I want to restore the ./[file] I know it's going to be something easy but for some reason I can't figure out what to search to get the relevant solution.
When you type ./[tab] and the file you're expecting doesn't come in linux shell, chances are you need to make the file executable:
sudo chmod a+x manage.py
Or you don't have sufficient permissions to access the file:
sudo chown user:group manage.py
(Be careful with the last one because it may lead to unexpected behaviour)

appcfg.py command not found

I am following the How to set up AppEngineBackend Tutorial on this website https://cloud.google.com/resources/articles/how-to-build-mobile-app-with-app-engine-backend-tutorial
My current environment is:
1.Windows 8(64-bit).
2.Java 7
3.Eclipse 4.2 with ADT(Its the eclipse that is preconfigured with ADT downloaded from the Android Website)
I have had many problems relating to Java, invalid AppEngine SDK, etc. ever since I have started this tutorial. I resolved many of them and have come to the point where data needs to be uploaded to AppEngine datastore from a .csv file using a script in an upload_data.sh file using the following command :
./upload_data.sh places.csv Place
The contents of upload_data.sh are:
!/bin/sh
appcfg.py upload_data
--config_file bulkloader.yaml --url="http://localhost:8888/remote_api" --filename $1 --kind=$2 -e
nobody#nowhere.com
Now the problem is that Windows does not support the .sh files. Also the file contains commands such as appcfg.py, --config_file,etc. For running the .sh file I downloaded Cygwin. Then I installed Python33 and also set the PythonPath environment variable to c:\python33. When I run the above command from Cygwin terminal I get the following:
./upload_data.sh: line 2: appcfg.py: command not found
./upload_data.sh: line 3: --config_file: command not found
./upload_data.sh: line 4: nobody#nowhere.com: command not found
Do I need to tell Cygwin about my python location ? If yes then how to do it?
Also I installed Python and Cygwin much later after I installed Google AppEngine SDK.Is this causing the problem?Are Cygwin and Python supposed to be installed before AppEngine SDK?Does installation of AppEngine SDK automatically inform Cygwin about appcfg.py,etc.?
Although it's not listed as a prerequisite, installing the Google App Engine SDK for Python (available at Google's App Engine SDK Download page) makes appcfg.py available to the command line.
During the installation of this SDK on a Mac, the installation puts appcfg.py on the PATH, thereby solving the "appcfg.py: command not found" error message. This may be similar for Windows.
Additionally, remove the line breaks (i.e., the "Next line" space) that occurs before the --config_file and nobody#nowhere.com words - the script only needs to be a single continuous line without any line breaks (the line should only overflow to the next line due to reaching the edge of the editor).
Here is a simple work around.There's no need to create a shell or .bat file. This should work for anyone and for any operating system using the terminal or command prompt. Your local server should be running in debug mode or in other words you can successfully navigate to http://localhost:8888/_ah/admin
Make sure you have downloaded and extracted Google App Engine SDK for Python to any location on your computer because the appcfg.py file is located in the parent directory extracted.
Put the following files "bulkloader.yaml and places.csv" in the parent folder extracted in step1 i.e. in the same directory where the appcfg.py file is located.
Run the following command directly in the terminal or command prompt:
python appcfg.py upload_data --config_file bulkloader.yaml --url=http://localhost:8888/remote_api --filename places.csv --kind=Place -e nobody#nowhere.com
Press enter when password prompt appears.. Enjoy!!!. Also you might need to wait for about a minute or two sometimes to confirm if the data is available from the datastore viewer.
The simplest solution (in my mind) to your question is to create a .bat file with following content:
python appcfg.py upload_data --config_file bulkloader.yaml --url="http://localhost:8888/remote_api" --filename $1 --kind=$2 -e nobody#nowhere.com
I haven't tested it so it might not work. Don't have a windows machine now. You'll need to put the folder of python.exe in your PATH environment variable.
Please use python 2.7 instead of python 3.3. I'm pretty sure Google App Engine doesn't support any Python 3.x yet.
Cheers
I also got this error on my Mac. It seems the newest version of Google App Engine not include appcfg.py in $PATH by default. The directory includes appcfg.py on my mac is $HOME/google-cloud-sdk/platform/google_appengine/, you can just add this directory in your $PATH and it should work.
If the reason you are searching for this fix is to error in appengine deployment since it states that another deploy is in progress and your app is built with maven, the easier way to rollback is to point your terminal to the directory from where you run the appengine deployments, and type $appengine:rollback.
I know the question is far from the past, but pay attention that appcfg.py is deprecated
Now you should use gcloud commands - https://cloud.google.com/appengine/docs/standard/java/tools/migrating-from-appcfg-to-gcloud

Sudoer statement syntax to source virtualenv activate file

I'm on a 64-bit Centos 5 Linux. This comes with Python2.4, but I needed 2.6 or higher to get psycopg2. I installed a virtual environment to run Python2.7.3 (based on this http://toomuchdata.com/2012/06/25/how-to-install-python-2-7-3-on-centos-6-2/) Now things seem to be working well when I'm logged in as root.
But I need to be able to use the virtualenv as a non-root user, joshmoe. (And start/stop postgresql as this other user)
The command for getting into the virtualenv is:
source /root/Python-2.7.3/projectdir/bin/activate
Understandably, when I run this command as joshmoe, I get a permission denied message:
-bash: /root/Python-2.7.3/projectdir/bin/activate: Permission denied
In an attempt to make this command available to joshmoe, I edited /etc/sudoers to include the following line:
joshmoe ALL=NOPASSWD: /root/Python-2.7.3/projectdir/bin/activate
Now from the joshmoe login, when I run:
sudo source /root/Python-2.7.3/projectdir/bin/activate
I get the following:
sudo: source: command not found
It seems pretty clear to me that I'm not using the sudoers file correctly to specify sourcing this file -- I seem to be giving access to that 'activate' file successfully, but not to the built-in source function. Either of following lines give syntax errors in sudoers:
joshmoe ALL=NOPASSWD: source
joshmoe ALL=NOPASSWD: source /root/Python-2.7.3/projectdir/bin/activate
I've found a good many examples of shudders statements. But I can't figure out the syntax that will make this work. I'm hoping once I get this one, I'll be able to give access to statements like 'service postgresql status' and so forth.
Your problem is that you user doesn't have root access to your virutalenv directory. You need to grant the user access for it to work, for example using:
sudo chmod o+x /root # grant access to root directory
sudo chmod o+rX /root/Python-2.7.3 -R # recursively grant access to everything in Python-2.7.3
source isn't a program, it's a shell butiltin which causes a script to be sourced in the current shell. sudo can only execute programs, not shell builtins, functions or aliases, that's why you get that error.
You can't run source as as sudo source; it's a built-in command for bash, not a program. What you want to do here is probably start a new shell as superuser using sudo -s.

Crontab / Launchd: OS X User Permissions, Environment Variables, Python Virtualenvs

I am trying to automate running a python script every minute on my mac, from a virtual environment. I am convinced that I don't properly understand permissions, paths, and environment variables in some crucial way that is preventing me from figuring this out.
I am an admin user with root rights enabled. I run HomeBrew, PIP and Virtualenv to manage python packages and virtual environments for different projects.
I would like to do the following every 60 seconds:
$ source /.virtualenvs/myenvironment/bin/activate
$ cd ~/desktop/python/
$ python myscript.py
$ deactivate
I have tried:
(a) writing my own plist for Launchd - and I believe these documents were well formed.
(b) programs which manage Launchd daemons and agents for you (both Launch Control and Lingon).
(c) I have tried simply editing the crontab (only lets me if I use the sudo command).
The python script, which works on command, pulls data from an online source and stores it in a sqlite table. I can tell the cron isn't running because the sqlite db isn't being touched.
Any thoughts would be enormously appreciated.
You don't say exactly what you tried with launchd and cron, but I'd bet you weren't using either of them correctly. Both are oriented toward running single, isolated commands (/programs), not sequences of shell commands. While it's possible to do this with a single cron job or launchd item, it's going to be messy. The simplest thing would be to write a shell script that does the sequence you want (be sure to include a shebang at the beginning, and enable execute permission on the script with chmod +x /path/to/script), and run that from either cron or launchd:
#!/bin/bash
source /.virtualenvs/myenvironment/bin/activate
cd ~/desktop/python/
python myscript.py
deactivate
I would not recommend using Automator to wrap the command sequence; it's designed for GUI-based scripting, and may not work right in a background-only job.
I have had this exact same problem and have recently solved it. Look here for the steps I took. Basically it deals with the shell needing the PYTHONPATH, not just the PATH.
So I'm still not sure why I can't configure Launchd or the Crontab to work for me: I still suspect it has to do with the environment variables.
If anyone else is having a tough time with this issue, I suggest creating an Automator application that runs the shell script you want to run, then use Lingon or Launch Control to run the Automator application file at whatever frequency you desire.

Categories