Make Python module available for all Linux users - python

I have a Python 2.7 question, if somebody can help.
When we install a Python module using pip, how do we make it available to all users? Please, see the example below (with module faker). The import works when I am root, but doesn’t work when I am ubuntu user.
I have already tried to install using option --system, and also changing umask, as recommended in some articles I have found. Didn’t work so far. Any ideas?
If we run "which python", both users point to the same one.
root#ip-172-30-244-157:/home/ubuntu#
root#ip-172-30-244-157:/home/ubuntu# python
Python 2.7.17 (default, Sep 30 2020, 13:38:04)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import faker
>>>
>>> exit()
root#ip-172-30-244-157:/home/ubuntu#
root#ip-172-30-244-157:/home/ubuntu#
root#ip-172-30-244-157:/home/ubuntu# exit
exit
ubuntu#ip-172-30-244-157:~$
ubuntu#ip-172-30-244-157:~$
ubuntu#ip-172-30-244-157:~$ python
Python 2.7.17 (default, Sep 30 2020, 13:38:04)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import faker
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named faker
>>>

Ok, I solved the issue.
In my case, the problematic module was "faker". But, when we install the faker, another additional module is installed as well (in this case - text-unidecode).
Then I uninstalled both modules, ran "umask 022" and re-installed the faker.
This solved the issue for all other users.
Thanks all for the help!

Related

ModuleNotFoundError: No module named 'psycopg2._psycopg' (Ipython)

This question has been asked before but none of the answers are satisfactory.
Using Command Prompt on Windows 10, there is no issue importing Psycopg2, which is located in
C:\Users\myusername\AppData\Roaming\Python\Python39\site-packages
For example:
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import psycopg2
>>>
In the IPython console of Spyder, I get an error:
Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 18:58:18) [MSC v.1900 64 bit (AMD64)]
Type "copyright", "credits" or "license" for more information.
IPython 7.19.0 -- An enhanced Interactive Python.
In [1]: import psycopg2
Traceback (most recent call last):
File "<ipython-input-1-7d2da0a5d979>", line 1, in <module>
import psycopg2
File "C:\Users\myusername\AppData\Roaming\Python\Python39\site-packages\psycopg2\__init__.py", line 51, in <module>
from psycopg2._psycopg import ( # noqa
ModuleNotFoundError: No module named 'psycopg2._psycopg'
Running sys.path indicates that the location of the package installation is there.
In [4]: sys.path
Out[4]:
['C:\\Program Files\\Spyder\\Python\\python37.zip',
'C:\\Program Files\\Spyder\\Python',
'C:\\Program Files\\Spyder\\pkgs',
'C:\\Program Files\\Spyder\\pkgs\\IPython\\extensions',
'C:\\Users\\myusername\\AppData\\Roaming\\Python\\Python39\\site-packages\\psycopg2',
'',
'C:\\Users\\myusername\\AppData\\Roaming\\Python\\Python39\\site-packages',
'C:\\Users\\myusername\\.ipython']
What do I need to do to make this work? It only recently started happening when I reset Windows 10 (uninstalls the operating system and reinstalls it from the cloud, while keeping your files).
This is a standalone installation of Spyder without Anaconda.
As we can see in your path, you have two versions of python installed in your machine.
One points to:
C:\Users\myusername\AppData\Roaming\Python\Python39\site-packages
which is python 3.9.
Another contains the spider code, which is python 3.7.
You just have to install your Psycopg2 in python 3.7 instance.

Accessing Python Modules Installed with Brew

I am trying to access "rdkit" module in python, but my python install doesn't seem to find the module. I installed it using brew as suggested here. I included the commands I use to reproduce the problem.
Is a simple fix just adding the "/usr/local/Cellar" to the python path? Symlinc the site-packages to the cellar? Candidly I did not understand the difference between pip and brew when updating my python, so my first thought is that the python path is not correct. Any suggestions greatly appreciated.
X:~\ python3 Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53) [Clang 6.0 (clang-600.0.57)] on darwin Type "help", "copyright", "credits" or "license" for more information.
>>> import rdkit Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'rdkit'
X:~\ which python3
/Library/Frameworks/Python.framework/Versions/3.8/bin/python3
X:~\ python3
Python 3.8.1 (v3.8.1:1b293b6006, Dec 18 2019, 14:08:53)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python38.zip',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/lib-dynload',
'/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages']
**#:/usr/local/Cellar\** ls
boost/ gettext/ libffi/ numpy/ sip/
boost-python3/ glew/ libidn2/ openblas/ sqlite/
cmake/ glib/ libmpc/ openssl#1.1/ tcl-tk/
ddclient/ glm/ libpng/ pandoc/ tree/
eigen/ gmp/ libtiff/ pcre/ webp/
fontconfig/ graphviz/ libtool/ pkg-config/ wget/
freeglut/ gts/ libunistring/ pyqt/ xz/
freetype/ icu4c/ mmtf-cpp/ python/
gcc/ isl/ mpfr/ qt/
gd/ jasper/ msgpack/ **rdkit/**
gdbm/ jpeg/ netpbm/ readline/
Details:
OS Catalina: 10.15.3

AttributeError: module 'bcrypt' has no attribute 'hashpw' for python

I don't know what I'm doing wrong. Please help
I ran into this issue as well and went through these steps to figure it out:
pip list double check that bcrypt is in that list
python --version which returned Python 2.7.15rc1
python3 --version which returned Python 3.6.7
I had an issue where python3 doesn't recognize the bcrypt package:
python
Python 2.7.15rc1 (default, Nov 12 2018, 14:31:15)
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>import bcrypt (pressed enter here)
>>>
vs
python3
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import bcrypt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'bcrypt'
then when double checking my file listing ran into the same issue #user2357112 suggested and renamed the "bcrypt.py" file I had created.
You stated that bcrypt.py is not the name of the file so I tried something else to recreate and built a new bcrypt.py file next to my pharaoh.py and reproduced the same error.
My code currently:
#!/usr/bin/env python
import bcrypt
# raw_input for pv2
user = raw_input("User value: \n")
password = raw_input("password: \n")
def pass_thru_crypt(user, password):
user_password = user + password
hashed = bcrypt.hashpw(user_password, bcrypt.gensalt())
if bcrypt.checkpw(user_password, hashed):
print("Indiana Jones just *bad_word* you up, Charlie!")
else:
print("You chose... poorly")
pass_thru_crypt(user, password)
I got the same error on my Ubuntu server. Installing these dependencies:
sudo apt-get install build-essential libffi-dev python-dev
worked for me. For your distro the dependencies might be different, look here: https://pypi.org/project/bcrypt/
yes it really works when we change the name of file like bcrypt.py to any.py but not bcrypt

How to use mechanize in pypy?

I used mechanize in Python, but peppy said
$ pypy
Python 2.7.9 (9c4588d731b7fe0b08669bd732c2b676cb0a8233, Mar 31 2015, 07:55:22)
[PyPy 2.5.1 with GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>> import mechanize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named mechanize
>>>> import sys
>>>> sys.path
['', '/usr/local/Cellar/pypy/2.5.1/libexec/site-packages/setuptools-14.3.1-py2.7.egg', '/usr/local/Cellar/pypy/2.5.1/libexec/site-packages/pip-6.0.8-py2.7.egg', '/usr/local/Cellar/pypy/2.5.1/libexec/lib_pypy/__extensions__', '/usr/local/Cellar/pypy/2.5.1/libexec/lib_pypy', '/usr/local/Cellar/pypy/2.5.1/libexec/lib-python/2.7', '/usr/local/Cellar/pypy/2.5.1/libexec/lib-python/2.7/lib-tk', '/usr/local/Cellar/pypy/2.5.1/libexec/lib-python/2.7/plat-darwin', '/usr/local/Cellar/pypy/2.5.1/libexec/lib-python/2.7/plat-mac', '/usr/local/Cellar/pypy/2.5.1/libexec/lib-python/2.7/plat-mac/lib-scriptpackages', '/usr/local/Cellar/pypy/2.5.1/libexec/site-packages']
Please tell me how to use mechanize in pypy.
I think I haven't create path but I don't know way.
PyPy does not automatically pick CPython paths. You either need to install mechanize separately (I suggest virtualenv) or you need to put path to it into sys.path or PYTHONPATH environment variable.

Compile Z3python?

I want to have Z3python on my Ubuntu 12.04 64-bit. I downloaded Z3 source, and compiled like below:
$autoconf
$./configure
$sudo make
$sudo make a
$sudo make o
Everything went well, but then I tried:
$ python
Python 2.7.3 (default, Sep 26 2012, 21:51:14)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import z3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named z3
It seems Z3python is not installed yet? I followed exactly the instructions in README, but it seems to miss something regarding Python binding?
please ignore, what i got is the old version of Z3.
a recommendation: please provide the source code of the latest Z3 in the homepage. i couldnt find it anywhere, then wrongly got the old version. finally, i had to download the latest version from the SourceControl, which was a bit tricky.

Categories

Resources