Change the python executable that Django 1.7 loads - python

I am building an app on Google Compute Engine using Django 1.7 and Python 2.7 within a Debian environment.
To get the mpl_toolkit library to work I have had to install Anaconda and its various modules within that environment, thereby over-riding the default "out-the-box" Bitnami setup.
I am currently unable to get the live server to run python from the Anaconda directory (/home/beastflow/anaconda2/bin/python) as it needs to.
Indeed, when I load the page I get the following line as part of the debug message:
Python Executable: /opt/bitnami/python/bin/python
What do I have to change in order to get Django to point to /home/beastflow/anaconda2/bin/python ?

Ok I found an answer (which avoids having to rebuild mod_wsgi). If you're using Bitnami, you can get python to load from a different path by changing /opt/bitnami/apache2/bin/envvars by adding a PATH line as follows (for example):
PATH=/home/beastflow/anaconda2/envs/django17/bin/:$PATH
export PATH
Then restart the apache server:
sudo /opt/bitnami/ctlscript.sh restart

Related

RHEL Permission Denied whilst trying to Run Robot Framework

I am setting up Robot Framework on RHEL 8.4. I have python 3.6 installed on my machine. However, when I try to run robot from within python virtual environment it throws
-ksh: robot: cannot execute [Permission Denied]
I also ran whereis robot and gave all permissions to the robot file.
The error happens when I am trying to run robot as a user other than root from within the virtual environment however, it works fine when run within virtual environment as root.
However, I am not keen to continue normal development as root and would like this to work via my normal user.
It sounds quite strange but upgrading PIP resolved the issue.
While creating a new project. Select the parent directory to the folder where the RobotFramework file is stored. It will solve the problem.
C:\Robot Framework

root:OSError while attempting to symlink the latest log directory - Apache Airflow

I am using Windows 10, python 3.6.4, and apache-airflow 1.10.2
I am trying to use Apache-Airflow for creating a workflow for my data pipeline. When I import airflow (the first time in a new session), I keep running into the following error:
import airflow
**WARNING:root:OSError while attempting to symlink the latest log directory**
import airflow
(No Error)
When I try to import aiflow again, I do not get this error. I checked my config file and it is pointing to the right directory (C:\Users\user\airflow, where my logs folder is).
To solve this error, when it comes to creating the symbolic link to the log folder, I am not sure how to approach this or if I should even do this manually?
I also create a environment variables to my airflow folder.Please let me know if more details are needed!
Airflow does not work on Windows directly. Instead, you can run it from a Linux virtual machine, Windows Subsystem for Linux (WSL), or Docker container.
To run it from a virtual machine, you can download VirtualBox along with the latest ubuntu-desktop ISO file. Now, you can create a virtual machine and install Airflow against it.

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.

Trying to change the Pylons version my website is using but this causes a DistributionNotFound exception

About a month ago I setup Pylons on my VPS in a virtual environment using the go-pylons.py script they provide. I've, since then, been working on my website and have it all up and running. It works great.
Recently though I discovered that I created my virtual python environment using Python2.5. I now want to change this to Python2.7
I've got Python2.7 running on my server and it all works great. I then created another virtual environment for Pylons and have that up and running. When I try to modify my website's mod_wsgi dispatch file to use the new environment, I get a DistributionNotFound exception. What could be causing this?
Here's my dispatch.wsgi file:
import site
import os
# New Python virtual environment
# site.addsitedir('/usr/local/pylonsenv/lib/python2.7/site-packages')
# Old Python virtual environment
site.addsitedir('/usr/local/pylons/lib/python2.5/site-packages')
os.environ['PYTHON_EGG_CACHE'] = '/home/samsu/python/egg-cache'
from paste.deploy import loadapp
application = loadapp('config:/home/samsu/python/mywebsite/production.ini')
When I change the addsitedir paths around and restart Apache, viewing the website throws the exception. As soon as I change it back, problem goes away.
Why can't I change virtual environments?
For starters, you must recompile/reinstall mod_wsgi against Python 2.7, you cannot just point it at a new virtual environment using a newer Python version. Likely that the older Python installation doesn't have new enough version of a package required by code installed into your Python 2.7 virtual environment.

Categories