How to change python-path of supervisor? - python

I'm working in a flask REST API using python3, supervisor and gunicorn. I have installed all the pip modules. when i run the supervisor's config file it shows following error. Any help would be appreciated.

Using virtual environment and install python 3.x to it. After that it works fine.

Related

"Command not found" when trying to run a python cli application with "sudo" on Ubuntu

I have the following problem (I searched for hours but could not get it to work):
I have a python cli application (coded by myself). I created a fresh conda environment (with python 3.9.1) and installed myapp locally via pip install . into the env. All went well and I could successfully run myapp from the cli without any errors.
However, part of my application needs myapp to be called with sudo. By doing so, I received the error: Command not found: myapp.
My question is now: Why is this happening (Is this, because my env is somehow not correctly activated or "linked"?)?. I read, that sudo uses some other paths in its $PATH. But how can I fix this?
Any ideas are welcome ;)
Many thanks in advance
Edit: I also tried this using virtualenv but same result. Furthermore, I could successfully run the same app with sudo on my other system, so it must has something to do with my Ubuntu (18.04) system.

flask run does not run after setting environment variables - Flask not found [duplicate]

When I run flask run on Windows, I get the following error
C:\Python37\python.exe: No module named C:\Python37\Scripts\flask
This was working previously, the issue started after I created a new env recently.
This was a bug introduced in Werkzeug 0.15.5. Upgrade to at least Werkzeug 0.15.6, which contains the fix. You can also run with python -m flask run instead to work around it.

Flask runs out of virtual environment

I was working in virtual environment but I removed the virtual environment folder in purpose. But I still can run flask restful application as below, while new empty virtual environment(there are no libraries in site packages but even application works like old virtual environment) is active.
flask run
I thought it should have been failed and complaining like:
no module named flask
, because I removed the old proper virtual environment and installed new one then activated it.
And here is the point, when I try the run the main script as below
python3 app.py
It complains as expected:
no module named flask
It seems that when I run with flask run it is not using virtual environment even virtual environment is active. Because of this reason I can't test my application with other python versions and can't test if requirements are installed and run in new other virtual environments. I couldn't understand this behavior of the flask for any help I appreciate.
Thanks in advance.
You may have Flask globally installed.
pip list | grep flask
You can remove that:
pip uninstall flask
or
Create virtualenv with --no-site-packages option:
virtualenv --no-site-packages venv
source venv/bin/activate
Well I figured out what is going on there.
Flask creates a directory named local in home and moved system's interpreter and dependencies there included by flask application that I wrote.
Then it deploys the application from there when run with flask run. So that means my flask app was not running with virtual environment as we guess.
So in that case I recreated my virtual environment and after installing dependencies I run with python3 app.py. Now it seems that it uses the virtual environment dependencies and interpreter.

Dev_appserver.py error when trying to deploy to Google AppEngine

I'm trying to deploy an example dart server using Google AppEngine. However when I run this python script (with the latest python version installed 3.5)
dev_appserver.py
I've also tried
dev_appserver.py --custom_entrypoint "dart bin/server.dart {port}" app.yaml
I get this error:
Traceback (most recent call last):
File "C:\Users\jkrie\AppData\Local\Google\Cloud SDK\google-cloud- sdk\bin\dev_appserver.py", line 11, in <module>
import bootstrapping.bootstrapping as bootstrapping
File "C:\Users\jkrie\AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\bootstrapping\bootstrapping.py", line 9, in <module>
import setup
ImportError: No module named 'setup'
I've also installed setuptools. I have to assume there is something wrong with my Google Cloud SDK install, but I really don't know what. Is python 3.5 too new and I need to try an older version?
GAE standard environment only supports Python 2.7 at this time, see Google App Engine Documentation.
Python 3.4 is supported only in the flexible environment, which has a different development flow.
Related: Google cloud dev_appserver.py unable to host laravel project locally
Indeed you have to use Python 2 for the standard App Engine environment for the time being.
If you have Python 3 installed, you can create a virtualenv using Python 2 using mkvirtualenv google --python=$(which python2) and run dev_appserver.py . in that environment.
This saves you the hassle of having to downgrade or symlink python to python2
Google could prepend the file with
#!/usr/bin/env python2
instead of
#!/usr/bin/env python
It would make their tools compatible with OSs that use python3 as default.
As #dan-cornilescu said GAE Standard Environment support only Python2.7
If you are in an environment with multiversion of Python, you could easly use Pipenv to run your dev_appserver.py with Python 2.7 version.
After you have installed pipenv globaly you could create a pipenv environment inside your project folder with Python 2.7
# pipenv install --twoo
Every time you need to run dev_appserver.py you should use this command
# pipenv run dev_appserver.py app.yaml
pipenv will use Python 2.7 to run your code. ;-)
I had this issue since I install both python2.9 and python3.6.
Quick way without uninstall python3 is just delete python3 path in environment variables while you are using GAE. Add them back when done with GAE.
I had the same problem with a very simple python35 app (now, a year later!)
I did create a python27 virtual environment which does work, but needed more workarounds.
The easiest thing is to just run python applicationmodule.py on the shell command line, ensuring you have this at the bottom:
if __name__ == '__main__':
# This is used when running locally. Gunicorn is used to run the
# application on Google App Engine. See entrypoint in app.yaml.
app.run(host='127.0.0.1', port=8080, debug=True)
If you want to run using dev_appserver.py then, I found I needed to run the following to make this work on the Google Cloud Shell:dev_appserver.py app.yaml --custom_entrypoint ./applicationmodule.py
In that case, make sure the applicationmodule.py doesn't have the if __name__ == '__main__': code. If you do have this, then it starts the same task again and complains about contention on port 8080.
This is different from other answers which have the --custom_entrypoint parameter looking more like the app.yaml entrypoint: entry.
At one point executing dev_appserver.py complained about executing applicationmodule.py (I forget exactly), so I did both chmod 777 and I added a #! pointing to my local python executable - it worked after having done both, but don't know if it was the chmod or the #! that did it.
App Engine now supports Python 3 from version 3.7.
If you still have Python 2 as the default, one way to specify version 3 is to add this to your ~/.zshrc or other startup scripts:
CLOUDSDK_PYTHON=python3
The environment variable can also take the full path to the preferred Python executable if it's not aliased to python3.
Here's a quick start guide and some differences between the support for versions 2.7 and 3.7.

Importing and debugging a Python Django project made in a different environment

I am working on a Django project that was created by another developer on a different machine. I see that in the root of the application, there is a .virtualenv directory. Is it possible to simply setup this project locally on my Windows machine using the project settings and Python version (the app uses 2.7), so that I can run it like a local Django application so debugging is feasible?
I have access to the development web server and have copied the full source of the app down to my Win7 machine but cannot seem to get things setup correctly to run the app locally so I can debug.
I currently have Python 2.7, 2.7.5 and 3.3.2 installed on my local dev machine. I would call myself pretty new to Django and Virtualenv.
If anyone has any guidance on how I can get my environment straitened out so I can run the app with debugging, I would be very thankful.
Thank you in advance.
Using a virtualenv environment created on a different machine is not recommended. There are things hard-wired for the particular system it was created on, and some apps may have components compiled for that particular system.
You should create a new virtualenv environment on your machine, install dependencies and move the Django project there.
Note on installing dependencies - there might be a file named requirements.txt somewhere. If it's there and it's kept up to date you can install all the dependencies by running a single command while in your virtualenv:
pip -r requirements.txt install
If you can't find it ask the other developer to create it. He just need to do this inside his own environment:
pip freeze > requirements.txt
I once faced the same problem and it took me so much time to configure another environment that I eventually had to create a VM with the same version of OS and libraries. I then made a raw copy of the project and it worked fine.

Categories