py-bcrypt fails to load - python

I have py-bcrypt installed in my virtualenv, but I can't get it to load the libraries in the virtualenv when the app is run through WSGI.
python /var/www/api-test/api.wsgi
Traceback (most recent call last):
File "/var/www/api-test/api.wsgi", line 3, in <module>
from api import app as application
File "/var/www/api-test/api.py", line 5, in <module>
import os, hashlib, bcrypt
ImportError: No module named bcrypt
However, running python and loading the library manually works fine
python
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bcrypt
>>> bcrypt
<module 'bcrypt' from '/var/www/api-test/api-env/local/lib/python2.7/site-packages/bcrypt/__init__.pyc'>
>>>

Turns out I needed to add the following to my api.wsgi file:
import site
site.addsitedir("/var/www/api-test/api-env/lib/python2.7/site-packages")

Related

Unable to import python module in custom environment

I am trying to import PyQt5 module in a custom python environment but it fails.
I have tested it with the system python and works fine
juan#juansphd:~/blender-2.82a-linux64/2.82/python/bin$ python3
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt5.QtCore
>>>
but when I run python3 of my custom environment, it fails to load it
juan#juansphd:~/blender-2.82a-linux64/2.82/python/bin$ ./python3.7m
Python 3.7.4 (default, Oct 8 2019, 15:23:02)
[GCC 6.3.1 20170216 (Red Hat 6.3.1-3)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import PyQt5.QtCore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5'
>>>
I have tried adding /usr/lib/python3/dist-packages, where PyQt5 is installed, into the sys.path but doesnt work neither
>>> sys.path.append("/usr/lib/python3/dist-packages")
>>> import PyQt5.QtCore
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PyQt5.QtCore'
>>>
How should I import the module?

Cannot import python naoqi library after upgrading Ubuntu 14.04 to 16.04

I have recently upgraded the system to 16.04 Gnome. The most troubling thing that I am facing is that I cannot import a NAOqi library for my work. The python version of this library was pretty simple to set-up. One just has to untar the file and then enter a path variable called PYTHONPATH pointing to this library and it worked like a charm in 14.04. Now since upgrade I am facing:
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import naoqi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dell/nao_sdk/pynaoqi/naoqi.py", line 7, in <module>
import qi
File "/home/dell/nao_sdk/pynaoqi/qi/__init__.py", line 72, in <module>
from _qi import Application as _Application
ImportError: libqipython.so: cannot open shared object file: No such file or directory
If I add a path variable:
export LD_LIBRARY_PATH=:/home/dell/nao_sdk/pynaoqi/
The error changes to:
Python 2.7.12 (default, Jul 1 2016, 15:12:24)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import naoqi
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/dell/nao_sdk/pynaoqi/naoqi.py", line 7, in <module>
import qi
File "/home/dell/nao_sdk/pynaoqi/qi/__init__.py", line 72, in <module>
from _qi import Application as _Application
ImportError: libboost_regex.so.1.55.0: cannot open shared object file: No such file or directory
Please help me what should I do to get it working? I have also used python 2.6.9 but same error occurs with error below.
ImportError: libboost_python.so.1.55.0: cannot open shared object file: No such file or directory
Installing libboost1.55 did the trick. 16.04 comes with libboost1.58 but naoqi is not yet compatible with it. Manual installation of libboost1.55 solved the import error.

Why I can not import the package in Python?

I use the code from here:
https://github.com/Jefferson-Henrique/GetOldTweets-python
And every time I try to import the file folder, import got, it will raise:
Traceback (most recent call last):
File "C:\Users\USER\Desktop\python\get_old_tweet\Main.py", line 1, in <module>
import got
File "C:\Users\USER\Desktop\python\get_old_tweet\got\__init__.py", line 1, in <module>
import models
ImportError: No module named 'models'
I have check the file and been pretty sure that they do have the file folder called models
And the file folder also contains __init__.py file.
So it should work well..
I have no idea how it doesn't work. Please help me!
Which version of Python do you use?
The library https://github.com/Jefferson-Henrique/GetOldTweets-python is written with Python 2.
Python 2 and Python 3 have a bit different behavior with import: https://www.python.org/dev/peps/pep-0404/#imports
Let me share example of import regarding your case:
$ python3
Python 3.5.0 |Anaconda 2.4.0 (x86_64)| (default, Oct 20 2015, 14:39:26)
[GCC 4.2.1 (Apple Inc. build 5577)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import got
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/viach/Downloads/GetOldTweets-python-master/got/__init__.py", line 1, in <module>
import models
ImportError: No module named 'models'
>>> ^C
KeyboardInterrupt
$ python2
Python 2.7.10 (default, Aug 22 2015, 20:33:39)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import got
So, quick solution for you: use Python 2 in your app which depends on GetOldTweets-python.
Python only searches its default library paths by default (including the running script path). So you need to put them in Python default library paths or append your module path to those paths.
To append the path array:
>>> import sys
>>> sys.path.append("path/to/the_module")
>>> import the_module
If above solution doesn't worked, try:
>>> from models import got
It depends on where you are importing from. In the repository you proved a link to models is a subfolder of got. Try this:
from got import models
You can use a Python3-compatible fork of GetOldTweets-python:
https://github.com/Mottl/GetOldTweets-python3

Virtual server ImportError: No module named fuzzywuzzy

Running an ec2 instance on aws; when attempting to run a script that imports several packages, all packages import correctly except one: 'fuzzywuzzy' (used for fuzzy string matching). I tried installing fuzzywuzzy from source code within the virtual server but aws reacted by auto-uninstalling it.
[ec2-user#ip-172-31-39-215 BearTrap]$ python
Python 2.7.9 (default, Apr 1 2015, 18:18:03)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import csv
>>> import string
>>> import ast
>>> import itertools
>>> from collections import OrderedDict
>>> import fuzzywuzzy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named fuzzywuzzy

Utils module not imported

I have downloaded this package of Python Utils , and tried to install it, by entering the folder and typing:
python setup.py install
The output seems fine: the package installed and all dependencies processed.
However, when I try to import:
$ python
Python 2.7.2 (default, Dec 12 2011, 16:10:05)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import utils
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named utils
What am I getting wrong?
The package is called python_utils, not utils. import python_utils should work.

Categories