Python import error when using PBS - python-2.7

My institute has some parallel computers with CentOS release 6.4 and Python2.6 installed. I want to use python 2.7, then I installed python 2.7.11 locally (without root permission, because I am not a root). My problem is that when I use Portable Batch System (PBS) to run python scripts, some import statements raise errors while packages were definitely installed (locally). For more detail, my scripts are:
test.py:
import ssl
test.pbs:
#!/bin/csh
cd working_dir
python test.py
When I run python test.py, no errors displayed.
When I submit the PBS job qsub test.pbs, the job was started and ended with error:
Traceback (most recent call last):
File "test.py", line 1, in
import ssl
File "/home/s1310007/python/lib/python2.7/ssl.py", line 97, in
import _ssl # if we can't import it, let the error propagate
ImportError: /home/s1310007/python/lib/python2.7/lib-dynload/_ssl.so: symbol SSL_get0_next_proto_negotiated, version libssl.so.10 not defined in file libssl.so.10 with link time reference
I guess when I ran python test.py on the login node (I logged in using ssh), the environment paths were set correctly. When the PBS job was started, the different environment paths were set, then the dynamic symbol SSL_get0_next_proto_negotiated was not resolved. I tried to modify my .cshrc or .dtprofile, .modulesbeginenv; but nothing works. Any suggestions? Thanks!

Related

uWSGI - ImportError: No module named google.oauth2.credentials

I am developing a Flask app that runs using uwsgi. I'm running into the following error ImportError: No module named google.oauth2.credentials.
When I run the Flask app using Flask's builtin dev server, the application runs without issues.
The problem seems to stem from how the google-auth module is installed. There's no __init__.py file in the google namespace folder in site-packages. The full path being /usr/local/lib/python2.7/site-packages/google.
I'm aware that python3.3 has implicit namespace packaging via PEP-420.
What I'm confused about is how the implicit namespace packaging works in python2.7. Does the installation process via pip do something special?
I'm also confused about what is different when running python2.7 via uwsgi.
Relevant versions
python 2.7.14
pip 9.0.3
uwsg 2.0.13
google-auth 1.4.1
Installed via pip (not using virtualenv)
https://github.com/GoogleCloudPlatform/google-auth-library-python
I've also included the following barebones test to reproduce the error.
test.ini
[uwsgi]
socket = 0.0.0.0:5001
plugins-dir = /usr/lib/uwsgi/
plugins = python
protocol = uwsgi
pythonpath = /usr/local/lib/python2.7/site-packages
callable = app
max-requests = 1000
master = True
lazy-apps = True
processes = 1
test.py
import google.oauth2.credentials
working command
python test.py
failing command
uwsgi --ini test.ini --wsgi-file test.py
failing result
When I run the above command, the program will fail due to the following ImportError.
Traceback (most recent call last):
File "test.py", line 1, in <module>
import google.oauth2.credentials
ImportError: No module named google.oauth2.credentials
Current workaround
My current workaround is to manually add an __init__.py file with the following (which is what is basically what is found in the google-auth repository, but for some reason is removed when installing via pip):
try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
import pkgutil
__path__ = pkgutil.extend_path(__path__, __name__)
Workaround 2
Another way I got the import working was by doing this:
import site
site.addsitedir('/usr/local/lib/python2.7/site-packages')
import google.oauth2.credentials
This seems to imply that uwsgi is not fully initialization python at least on initial start up.
I got the hint to try site.addistedir from this answer: https://stackoverflow.com/a/15209116/177646
Turns out the problem was a uWSGI configuration error on my part. Since I'm not using virtualenv, I needed to set PYTHONHOME to the correct value, which is /usr/local in my case. In the uwsgi configuration, this can be specified via the home parameter. Once this is set, then python seems to work normally.
Once the PYTHONHOME is correctly set, this allows the google_auth-1.4.1-py3.6-nspkg.pth file to be found.
This also explains why I had to always import /usr/local/lib/python2.7/site-packages in my PYTHONPATH. Once the PYTHONHOME is set, then I no longer needed to add site-packages to my PYTHONPATH.
Example:
[uwsgi]
socket = 0.0.0.0:5001
plugins-dir = /usr/lib/uwsgi/
plugins = python
protocol = uwsgi
home = /usr/local
callable = app
max-requests = 1000
master = True
lazy-apps = True
processes = 1

ImportError when running a Python script from within a Shell script

I am trying to write a small shell script, which at the end invokes a small Python script. The end of shell script is as follows:
echo $pythonFilePath
cd $pythonFilePath
python Python-webtest.py
I have made the Python-webtest.py as executable. However, when the shell script is executed, I get the following error, coming from the python script
Traceback (most recent call last):
File "Python-webtest.py", line 2, in <module>
from selenium import webdriver
ImportError: No module named selenium
The following is my python script
#!/usr/bin/env python
from selenium import webdriver
webdriver.Firefox()
I have no issues when I try to run the stand alone python script and executes without any issues.
I try on my machine and it's working, the unique difference that you didn't mentioned and maybe is the reason for why it's not working for you is that I introduced selenium in the windows environment variables.
Right click on Computer->properties (or just go to Control
Panel\System and Security\System)
Click the Advanced system settings link.
Click on Advanced
Click Environment Variables.
In the section System Variables,find the PATH environment variable
and select it.
Click Edit. If the PATH environment variable of selenium does not
exist in the list,add it at the end and save.
IMPORTANT: don't delete the existing environment variables
I think I found the problem. I had a python installation from anaconda and while, I had done a pip install it appears to have done within the anaconda installation directory. I completely removed anaconda and then did pip install -U selenium and ran the shell script and without any issues, the python script also did its job.

gcloud command suddenly doesn't work at all

All gcloud commands suddenly give this error:
ERROR: gcloud failed to load: No module named google.appengine.ext
This usually indicates corruption in your gcloud installation or
problems with your Python interpreter.
Please verify that the following is the path to a working Python 2.7
executable:
/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
If it is not, please set the CLOUDSDK_PYTHON environment variable to
point to a working Python 2.7 executable.
If you are still experiencing problems, please reinstall the Cloud SDK
using the instructions here:
https://cloud.google.com/sdk/
Here are some relevant details and things that I've tried:
Mac 10.11.6
Python 2.7.8 at /Library/Frameworks/Python.framework/Versions/2.7/bin/python
Python otherwise works fine
I completely removed google-cloud-sdk and redownloaded from https://cloud.google.com/sdk/
Tried rebooting
Tried "export CLOUDSDK_PYTHON=/Library/Frameworks/Python.framework/Versions/2.7/bin/python" but it didn't help. Also added this line to my .bash_profile
Anyone else having this problem or can suggest a fix?
I have a fix below, but I'll happily award the answer to anyone who can explain what is going on.
I had the same issue . I solved it by using the default python2.7 in Ubuntu
Type this in termimal
export CLOUDSDK_PYTHON=/usr/bin/python
Not sure if this will work the same on Windows
I followed the answer here, worked for me
https://stackoverflow.com/a/59816812/2210667
brew switch openssl 1.0.2q (or whatever latest version you have from ls /usr/local/Cellar/openssl)
I figured out what was causing the problem, though I don't understand what is going on... When reinstalling gcloud I skipped the install script (./google-cloud-sdk/install.sh) since it is an optional step and I already had the needed lines in my bash profile.
When running this script, however, I got this error:
$ ./google-cloud-sdk/install.sh
Welcome to the Google Cloud SDK!
Traceback (most recent call last):
File "/Users/.../google-cloud-sdk/bin/bootstrapping/install.py", line 8, in <module>
import bootstrapping
File "/Users/.../google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 17, in <module>
import oauth2client.contrib.gce as gce
File "/Users/.../google-cloud-sdk/lib/third_party/oauth2client/contrib/gce.py", line 23, in <module>
import httplib2
File "/Users/.../google-cloud-sdk/lib/third_party/httplib2/__init__.py", line 29, in <module>
import email
File "/Users/.../GIT/GAE_Project/email.py", line 1, in <module>
ImportError: No module named google.appengine.ext
A file I recently created in my GAE project named email.py broke gcloud!?! Renaming this file fixed gcloud.
This is my PYTHONPATH:
/Users/.../google-cloud-sdk/platform/google_appengine:/Users/.../GIT/GAE_Project
So even though the Google cloud libraries come before my GAE project in my PYTHONPATH, a file in my GAE project broke gcloud.

"ImportError: No module named path" showing when running software in ubuntu 12.04

I am running one software in ubuntu 12.04. It requires python. I have python 2.7.3 on ubuntu. When try to run command ./cmdsadit sim -c ./Example/SimExample.py it shows following
jayram#ubuntu:~/sadit$ ./cmdsadit sim -c ./Example/SimExample.py
[warning] socketIO_client is not found. Real-time ability is disabled
--> Use [matplotlib] as plot backend
--> [warning] cannot import sql related function, reading for sql server is not supported
WARNING:util:Cannot find [socketIO_client], real-time ability is disabled.
WARNING:util:Cannot import sql related function, reading for sql server is not supported
Traceback (most recent call last):
File "fs.py", line 10, in <module>
from networkx.algorithms.traversal.path import single_source_dijkstra_path, dijkstra_path_length
ImportError: No module named path
jayram#ubuntu:~/sadit$
Some initial line screenshot of fy.py file is given below
How do I solve this error?
The error is self explanatory, your import from path module is incorrect
It should be
from networkx.algorithms import single_source_dijkstra_path, dijkstra_path_length

Python can't locate modules which I have created

I am new to programming and have recently installed the Enthought Canopy distribution and can't seem to import certain modules.
Python 2.7 MacOSX
Numpy works when I import it, however other modules which I have created or downloaded as a simple module.py file return this error message:
import numfun1
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-297-cb46e477a372> in <module>()
----> 1 import numfun1
ImportError: No module named numfun1
Could it have something to do with where those modules are saved? If so, how do I point python in their direction? or where should I put those modules so that Python sees them.
Thank you in advanced for your suggestions.
Information about the module search path is included in the official Python tutorial: http://docs.python.org/2/tutorial/modules.html#the-module-search-path.
A lot of python libraries come with a setup.py script that will automatically install them into locations that are on the search path.
The installation process can be even more automated by using a Python package manager like pip.
If you create a module you must put it where your script is.