AttributeError: module 'bcrypt' has no attribute 'hashpw' for python - 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

Related

Make Python module available for all Linux users

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!

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

library not loaded: libssl.1.0.0.dylib reason: image not found

I am getting the following error (on osx):
Traceback (most recent call last):
File "./permission_analysis.py", line 9, in <module>
import psycopg2
File "/Library/Python/2.7/site-packages/psycopg2/__init__.py", line 50, in <module>
from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID
ImportError: dlopen(/Library/Python/2.7/site-packages/psycopg2/_psycopg.so, 2): Library not loaded: libssl.1.0.0.dylib
Referenced from: /Library/Python/2.7/site-packages/psycopg2/_psycopg.so
Reason: image not found
So this looks a lot like this question:
Psycopg2 image not found
Except that the most popular upvoted answer doesn't work:
$ sudo ln -s /Library/PostgreSQL/9.2/lib/libssl.1.0.0.dylib /usr/lib
$ sudo ln -s /Library/PostgreSQL/9.2/lib/libcrypto.1.0.0.dylib /usr/lib
If I try to do either of those commands, it says the file already exists.
I feel your pain with trying to get Psycopg2 to work on Mac. I tried for ages, but i got it working in the end.
I asked this question and answered it here
Thanks guys.
#maxymoo I went with your suggestion. I have installed anaconda2. The install updated my path to include /anaconda/bin.
Then using the navigator I installed pyscopg2. Now I am able to use this in the shebang and my scripts execute fine and i'm able to import this module.
Gurmokhs-MBP:rest Gurmokh$ python
Python 2.7.12 |Anaconda 4.2.0 (x86_64)| (default, Jul 2 2016, 17:43:17)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://anaconda.org
>>> import psycopg2
if psycopg2.connect("dbname='postgres' user='postgres' host='localhost'"):
... print "connection made"
...
connection made
>>>

Installing python

I have tried to install Python 3.4 on Windows 7 using the following guide
I have added the following to my Path in system environmental variables
C:\Python34\;C:\Python34\Scripts;
When I open up the Python command line and type the following (as instructed in the tutorial) I receive an error message printed below
Python 3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:15:05) [MSC v.1600 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
python --version <- what i type
Traceback (most recent call last):
File "", line 1, in
NameError: name 'python' is not defined
Can anyone help me out?
You need to type python --version from the command line. Not when you are already running python.
As has been mentioned, you need to run your command from the command prompt:
python --version
However, if you are in the python interpreter, you can find the current version with this code:
import sys
print (sys.version)

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