Apache2 cannot find modules in user site-packages - apache

When I run pip3 install ... the packages are installed in ./.local/lib/python3.7/site-packages however when running my app Apache cannot import these modules. It can only import base python packages or if the packages are inside the /usr/lib/python3.7 directory. Not sure what do here. Did a lot of complicated SO and Google searching on permission and www-data user but everything fails. This is a GCP LAMPs distribution.
I tried:
setting PYTHONPATH in ~/.bashrc
adding to /etc/apache2/sites-enabled/lamp-server.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName myproject
WSGIDaemonProcess myproject python-path=./.local/lib:./.local/lib/python3.7/site-packages/
Adding to path in cgi script
import cgi, cgitb
import sys
import site
import cgitb.enable()
sys.path.append(['./.local/lib/python3.7','./.local/lib/python3.7/site-packages'])
try:
import rdkit
import chembl_webresource_client
# import sklearn
except ImportError as error:
# Output expected ImportErrors.
print(error)
This give me:
No module named 'chembl_webresource_client' because I copied the rdkit folders to /usr/lib/python3.7 folder manually

Related

Creating a python module that calls functions from a module that requires installation in google colab

in my colab notebook, I ran
!pip install unusual_module
from unusual_module import useful_function
Then I defined my_function in my collab notebook. This definition included a call touseful_funcion. This worked fine.
Since then I have created my_own_module.py which includes my_funcion. This .py is at the root directory of the notebook.
My notebook now begins with:
!pip install unusual_module
from unusual_module import useful_function
import my_own_module
These all run fine. However when i run my_funcion i get NameError: name 'useful_function' is not defined
I've tried:
having both !pip install unusual_module and from unusual module import useful_function at the start of my_own_module.py
from unusual module import useful_function at the start of my_own_module.py
both result in
NameError: name 'useful_function' is not defined
Why is this? and how do I fix it?

ValueError: not enough values to unpack (expected 2, got 1) when I try to import numpy in python3

I have python3.7.4 installed and when I install numpy using pip3 it says installation is successful. When I am in my main directory I run python3 and type in import numpy and it works fine . However, when I cd into my python3 directory where I keep all my .py files and I try to run a python file that imports numpy I get an . If I am in this python3 directory and I run python3 I open the same version of python however when I try to run import numpy I get the same . My homework3.py file only contains one line which is import numpy as np just to see if it runs which it does not.
I had a file in the same directory where Python is installed with the same name as "numbers.py" so I deleted the extra file and everything worked fine.

Migrating Trac 0.12 from Debian wheezy to Trac 1.0.2 on jessie including all plugins

I try to migrate a trac installation from a debian wheezy server to another debian jessie.
If I copy all files to the new server I get the message, that I have to upgrade with trac-admin /var/trac/blimus upgrade, which seems to work, but it seems not to update all plugins.
for example I had a plugin installed in the old trac, that lets you login on a webpage instead of the htaccess popup.
On the new server I now get the error
Error: Not Found
No handler matched request to /login
How do I get the web-login back?
Is there a way to analyze the old trac folder, which plugins were installed, so I can install the missing ones in the new installation?
I checked the new trac.ini file and added the missing options, this is my trac.ini
These are my versions:
# trac-admin --version
Warning: Detected setuptools version 5.5.1.
Welcome to trac-admin 1.0.2
If the plugin were installed in the Environment plugins directory as eggs, they will be carried over to your new server when you copied the the environment. However, you almost certainly need to upgrade to newer versions, so I suggest deleting the eggs from the Environment plugins directory. The plugins might also have been installed in Python's site-packages. Or they could have been installed using Debian's package manager, I'm not sure if plugins are available there, you might want to search using apt. See Trac Plugin documentation.
Which version of Trac are you running now? I assume it's 1.2.3.
You trac.ini shows that you have 3 plugins installed, and you no longer need one of them in Trac 1.2 (NeverNotifyUpdaterPlugin). You should install these two:
* AccountManagerPlugin
* XmlRpcPlugin
I don't know if Debian packages those for distribution. If not, you can install them with pip.
This instruction will work on Debian jessie (Trac 1.0.2), as well as Ubuntu 14.04 trusty (Trac 1.0.1)
Prerequisites
On your old Debian wheezy server:
# cd ~/
# tar -cvzf trac-example.tgz /var/trac/example
# cp /var/trac/example/conf/trac.ini trac.ini-example
# update your trac.ini-example to match new settings
Installation on the new server
#!/usr/bin/env bash
####################### config ##############################
INSTALLPATH=/var/trac/example
DEPLOYPATH=/var/www/trac-example
# where you store your tgz backup and the new trac.ini file
BACKUP_PATH=~/
#############################################################
# install packages without user interaction:
export DEBIAN_FRONTEND=noninteractive
apt-get -y install unzip apache2 trac trac-accountmanager trac-xmlrpc libapache2-mod-python libapache2-mod-python-doc libapache2-mod-wsgi
a2dismod python
a2enmod rewrite
# add trac user for apache WSGIDaemonProcess:
adduser --shell /bin/sh --no-create-home --disabled-password trac
mkdir -p /home/trac/.keep-for-mod_wsgi
mkdir -p /var/trac
# extract the tar-gz file of the trac installation from the old server
tar -C /var/trac/ -xvzf $BACKUP_PATH/trac-example.tgz
# copy your new config here:
cp $INSTALLPATH/conf/trac.ini $INSTALLPATH/conf/trac.ini-backup
cp $BACKUP_PATH/trac.ini-example $INSTALLPATH/conf/trac.ini
# remove old plugins and eggs
rm -rf $INSTALLPATH/plugins/nevernotifyupdaterplugin-0.0.* $INSTALLPATH/eggs/*
# update Trac
cd $INSTALLPATH/
trac-admin $INSTALLPATH upgrade
trac-admin $INSTALLPATH wiki upgrade
trac-admin $INSTALLPATH deploy $DEPLOYPATH/
chmod ugo+x $DEPLOYPATH/cgi-bin/ $DEPLOYPATH/htdocs/
# downgrade genshi from 7.3 to 6.0 due to error when adding an attachment:
easy_install -U Genshi==0.6
# upgrade setuptools
easy_install -U setuptools==1.4.2
# install neverNotifier Plugin
# (This is still needed on trac 1.0.x, on 1.2 ist is obsolete)
cd /tmp
wget "https://trac-hacks.org/browser/nevernotifyupdaterplugin/1.0?r│
ev=17630&format=zip"
unzip 1.0\?r*
cd 1.0/
python setup.py bdist_egg
cp dist/nevernotifyupdaterplugin-1.0-py2.7.egg $INSTALLPATH/plugins/
# setup hosts file
VHOST=$(cat <<EOF
<VirtualHost *:80>
Alias /trac/chrome/common $DEPLOYPATH/htdocs/site/common
Alias /trac/chrome/site $DEPLOYPATH/htdocs/site
<Directory "$DEPLOYPATH/htdocs">
Require all granted
</Directory>
<Location "/trac">
SetEnv TRAC_ENV "$INSTALLPATH"
SetEnv PYTHON_EGG_CACHE "$INSTALLPATH/.python-eggs"
SetEnv TRAC_ENV_INDEX_TEMPLATE $INSTALLPATH/templates
</Location>
##trac mit mod_wsgi
WSGIDaemonProcess trac user=trac group=trac threads=25
WSGIScriptAlias /trac $DEPLOYPATH/cgi-bin/trac.wsgi
<Directory $DEPLOYPATH/apache>
WSGIApplicationGroup %{GLOBAL}
Require all granted
</Directory>
<Directory $DEPLOYPATH/cgi-bin>
Require all granted
</Directory>
<Directory $DEPLOYPATH/htdocs/common>
Require all granted
</Directory>
<Directory $DEPLOYPATH/htdocs/site>
Require all granted
</Directory>
</VirtualHost>
EOF
)
# apache config
echo "${VHOST}" > /etc/apache2/sites-available/trac-example.conf
a2ensite trac-example
On a fresh installed systen, disable the default apache config
rm /etc/apache2/sites-enabled/000-default.conf
then restart apache
service apache2 restart

Using Tensorflow with GPU on Debian 8.10 Jessie

I have Tensorflow installed on the Debian Server using virtual environment
export url=https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow_gpu-1.5.0-cp34-cp34m-linux_x86_64.whl
pip3 install --user $url
This installs tensorflow-gpu==1.5.0 on ~/.local/lib/python3.4/site-packages
But when I import tensor flow package in Ipython notebook like:
import tensorflow as tf
I get the following error:
ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory
In /usr/local/cuda-8.0 I do have ./lib64/libcublas.so.8.0. Then why can't Tensorflow find it? Now do I need to install cuda-9.0? Unfortunately, I don't have root permissions on the system. Is there a way around this?
Thanks in advance,

How to install modules for Python 2.7 on Ubuntu 10.10?

On Ubuntu 10.10, I am unable to install lxml to python 2.7. Here are the steps I take.
sudo su -
apt-get install python2.7
apt-get install python-lxml
Note when running the install for python-lxml package, the following appeared:
INFO: using unknown version '/usr/bin/python2.7' (debian_defaults not up-to-date?)"
Importing the module in python2.6 (the version that comes standard with Ubuntu) works. However, importing the module under python2.7 does not. So how does one install Python modules to a non-default Python installation?
Try to install libxml2, libxml2-dev, libxslt, libxslt-dev, python-dev. These are header files. Then try to install lxml again.
On Ubuntu 10.10 the python packages installed from the repositories get installed to /usr/lib/python2.6/dist-packages so one option is to add this path to your $PYTHONPATH environmental variable so python2.7 will look to the python2.6 directory for the libs.
What I've done on Ubuntu 10.10 is add
export PYTHONPATH="$PYTHONPATH:/usr/lib/python2.6/dist-packages"
to my .bashrc file, and also to my .gnomerc file. This sets the $PYTHONPATH for python instances started from the shell or from the gnome desktop. You should then be able to import the python libs which you have installed from the Ubuntu repositories in python2.7.
.bashrc and .gnomerc are both located in your home directory; you might have to create .gnomerc if it doesn't already exist. And one caution: I had a syntax error in my .gnomerc which stopped the gnome desktop from loading, and I couldn't log in. I had to use a recovery console to fix this syntax error and then I could log in again.
This seems a little hackish to me, so I'm interested in hearing better solutions.
Another solution might be to use the following code:
try:
from lxml import etree
except ImportError:
try:
# Python 2.5
import xml.etree.cElementTree as etree
except ImportError:
try:
# Python 2.5
import xml.etree.ElementTree as etree
except ImportError:
try:
# normal cElementTree install
import cElementTree as etree
except ImportError:
try:
# normal ElementTree install
import elementtree.ElementTree as etree
except ImportError:
print("Failed to import ElementTree from any known place")
[Source]
This will import lxml if it is available, or the original ElementTree otherwise.
I use this code for my application on Google App Engine (using Python 2.7): on the server it will use lxml, on my machine it will use ElementTree.
I have one easiest trick Just open synaptic package manager type "python-lxml" in search box it will show you all the dependencies and available packages select packages which you want to install and hit apply.