I had python3.5 minimal in my Ubuntu 16.04. I upgraded it to python3.6 using the following commands.
sudo add-apt-repository ppa:deadsnakes/ppa -y && sudo apt-get update
sudo apt-get install python3.6
Now, when i try to import bson or pymongo in python3.6.12 env, i get "No module name bson/pymongo".
But when i try to import bson or pymongo in python2.7, it gets imported without any error.
What am i missing?
Thanks in advance.
Python 2 and Python 3 install packages in different places. Any packages you installed for Python 2 will not be visible or usable from Python 3.
To use them from Python 3, install them again using Python 3.
Related
I'm trying to use Notion API for some automation processes but I am having some trouble importing the packages and I already try a lot of imports. I've this code:
from notion_database.database import Database
my_token = "my_token"
D = Database(integrations_token=my_token )
print(D.list_databases(page_size=100))
To run this code I made the following imports:
pip install notion-database
pip install notion-py
pip install "notion==0.0.25"
pip install notion
All of them were installed correctly and I don't have my script name as "notion.py" :D
But when I run my code I got:
from notion_database.database import Database
ModuleNotFoundError: No module named 'notion_database'
Does anyone know what I am doing wrong?
Thanks for the help!
It looks your code is fine.
More likely, your python and pip points onto two different python versions.
I would suggest you create an environment (virtualenv or pyenv) and reinstall the packages using this command:
sudo python -m pip install notion-database
sudo python -m pip install notion-py
sudo python -m pip install "notion==0.0.25"
sudo python -m pip install notion
maybe you have not install notion successfully.
try to replace pip install notion
to pip install notion --user
,after that maybe there is no error with run "import notion".
good luck!
Does Python version 2.7 have bcrypt in its library?
I tried import bcrypt and got the following error:
Traceback (most recent call last):
File "register.py", line 7, in <module>
import bcrypt
ImportError: No module named bcrypt
bcrypt is available as a pip package for python 2.7, so yes, it supports python 2.7.
It does not come by default with your python installation though, you need to pip install bcrypt in your python environment to import bcrypt successfully
As jonsharpe mentioned, bcrypt is not in standard python library, but it can be easily installed and used in python 2.7
From terminal, just try
sudo pip install bcrypt
And you should be able to do
import bcrypt
without issue.
The following error for me was caused by an upgrade in the version of python.
There are two ways to fix, you can downgrade to the old version of python or you can purge that old version by running the following commands.
sudo apt-get clean
&&
sudo apt-get autoremove --purge
&&
sudo apt-get remove python
&&
sudo apt-get autoremove
Then create a virtualenv with the new python version and install your dependencies. All the best!
I'm currently working on a project with my raspberry pi. In this project I want to connect my raspberry to google firebase, therefore I have to use:
import pyrebase
I have installed pyrebase in terminal with:
pip install pyrebase
Also I'm aware that pyrebase doesn't support python 2, so i'm using python 3.4.2. I don't know why python can't find it, any ideas or suggestions?
If you have multiple versions of python installed, it may be confused on which version of pyrebase to install.
Try:
pip3 install pyrebase
Try to import like this:
from pyrebase import pyrebase
Works for me.
pip3 install pyrebase4
if this doesn't work
write this:
pip install pycryptodome
then
pip install pyrebase
Check if the pip you're using is working with your python version
pip --version
pip 8.1.2 from c:\python27\lib\site-packages (python 2.7)
Mine is working with python 2.7.
If you're working with the right python version try pip freeze or pip list to see the list of currently installed libraries, and check if the one that you're trying to install is there.
The Best Option is to install Ubuntu Mate in your raspberry pi as i have tried this on debian and got the same problem for absolutely no reason!! so i installed ubuntu mate and here you go it worked!!
pip install pyrebase <br>
This is for python 2.x
Please install python 3.x and pip3.x instead, then run
`pip3.x install pyrebase`
I was getting the "import error" of pyrebase. After checking this link I got the idea of problem, but was unable to find proper solution. After struggling for a day, I got the Solution. As I was using PYREBASE for my Engineering Project, I re-installed RASPBIAN-JESSIE stretch image on SD. Removed python2.7 and python3 and again installed python3 and then installing pyrebase and with frequent reboots. but it worked!
$ sudo apt-get remove python2.7
$ sudo apt-get remove python3
$ sudo reboot
$ sudo apt-get install python3
$ wget https://bootstrap.pypa.io/get-pip.py
$ sudo python3 get-pip.py
$ pip3 freeze #(displays about 15 lines, if pip is installed correctly)
$ pip3 list #(displays about 15 lines)
$ sudo pip3 install pyrebase
and now,
from pyrebase import pyrebase
and it did not gave import error.
For some reasons pyrebase Lib will only works in pycharm ide.
donwload Pycharm IDE Here !
1- Start Clean:
pip3 uninstall pyrebase4
pip3 uninstall pyrebase
2- Install Lib
pip3 install pyrebase
3- Restart your PC.
4- Run pycharm ide as administrator
5- Import it in Python:
from pyrebase import pyrebase
You should have it to work now!
This will work on latest versions of python
pip install pyrebase4
I'm currently running Ubuntu 12.10 and tried to get pymongo to work properly under python3. Things I have tried:
1. apt-get install python-pymongo
2. python setup.py install #from git source
3. easy_install pymongo
4. easy_install pymongo3
5. pip install pymongo
6. pip install pymongo3 #needed a fix in the download script
I have also removed and cleaned between the installations as best as I could.
If I import pymongo:
In [1]: import pymongo
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-ec8fdd1cd630> in <module>()
----> 1 import pymongo
/usr/local/lib/python3.2/dist-packages/pymongo-2.4.2_-py3.2-linux-x86_64.egg/pymongo/__init__.py in <module>()
55 return '.'.join(map(str, version_tuple))
56
---> 57 version = get_version_string()
58 """Current version of PyMongo."""
59
/usr/local/lib/python3.2/dist-packages/pymongo-2.4.2_-py3.2-linux-x86_64.egg/pymongo/__init__.py in get_version_string()
51
52 def get_version_string():
---> 53 if isinstance(version_tuple[-1], basestring):
54 return '.'.join(map(str, version_tuple[:-1])) + version_tuple[-1]
55 return '.'.join(map(str, version_tuple))
NameError: global name 'basestring' is not defined
The error is the same as pymongo FAQ but for me it doesn't matter where I'm located.
My theory is that the python2 version of pymongo has mistakenly been added python3.
In case I needed it in the future.
Installation of pymongo in ubuntu13 for python3
(1)Do not install the pymongo directly in the ubuntu software center; they are for old version of python (before version 3)
If you install it, you'll not be able to use pymongo in python3:
(2)You should install a specific python package installer for python 3: python3-pip
(3)use the pip-3.3 command python3-pip package provided, run the following command in terminal of unbuntu to install pymongo:
pip-3.3 install pymongo
If you don't have super user privilege, run it with sudo
sudo pip-3.3 install pymongo
(4)Then you should have no difficulty in install pymongo which can be used in python3. To verify it, type in IDLE:
(5)You can also install pymongo3 without difficulty in the terminal:
pip-3.3 install pymongo3
But there is no need to install it because all its functionalities are included in current pymongo package now.
Installation with pip3 worked for me
sudo pip3 install pymongo
To use pip3, As a prerequisite Python 3 copy of pip has to be installed which can be done as follows
sudo apt-get install python3-pip
Download the latest pymongo(3.4.0) from https://pypi.python.org/pypi/pymongo#downloads
Extract the files: tar -zxvf pymongo-3.4.0.tar.gz
Run the installation by firing: python3 setup.py install
Note: Of course you will need to fire the aforementioned command inside your extracted pymongo directory. You may also need to run it as root otherwise you will get write permission issues. I am using CentOS 7 and it worked like breeze!.
It should work with
sudo python3.2 setup.py install
but it doesn't for some reason
better of downloading the source for distributed and pip (and install them in this order) by
sudo python3 setup.py install #distributed
sudo python3 setup.py install #pip
sudo pip-3.2 install pymongo
In installation process of OpenERP 6, I want to generate a config file with these commands:
cd /home/openerp/openerp-server/bin/
./openerp-server.py -s --stop-after-init -c /home/openerp/openerp-server.cfg
But it always showed the message: ImportError: No module named psycopg2
When I checked for psycopg2 package, it's already installed. Package python-psycopg2-2.4.5-1.rhel5.x86_64 is already installed to its latest version. Nothing to do. What's wrong with this? My server is CentOS, I've installed Python 2.6.7.
Step 1: Install the dependencies
sudo apt-get install build-dep python-psycopg2
Step 2: Run this command in your virtualenv
pip install psycopg2-binary
Ref: Fernando Munoz
Use psycopg2-binary instead of psycopg2.
pip install psycopg2-binary
Or you will get the warning below:
UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: http://initd.org/psycopg/docs/install.html#binary-install-from-pypi.
Reference: Psycopg 2.7.4 released | Psycopg
I faced the same issue and resolved it with following commands:
sudo apt-get install libpq-dev
pip install psycopg2
Try installing
psycopg2-binary
with
pip install psycopg2-binary --user
Please try to run the command import psycopg2 on the python console. If you get the error then check the sys.path where the python look for the install module. If the parent directory of the python-psycopg2-2.4.5-1.rhel5.x86_64 is there in the sys.path or not. If its not in the sys.path then run export PYTHONPATH=<parent directory of python-psycopg2-2.4.5-1.rhel5.x86_64> before running the openerp server.
Import Error on Mac OS
If psycopg2 is getting installed but you are unable to import it in your .py file then the problem is libpq, its linkages, and the library openssl, on which libpq depends upon. The overall steps are reproduced below. You can check it step by step to know which is the source of error for you and then you can troubleshoot from there.
Check for the installation of the openssl and make sure it's working.
Check for installation of libpq in your system it may not have been installed or not linked. If not installed then install it using the command brew install libpq. This installs libpq library. As per the documentation
libpq is the C application programmer's interface to PostgreSQL. libpq is a set of library functions that allow client programs to pass queries to the PostgreSQL backend server and to receive the results of these queries.
Link libpq using brew link libpq, if this doesn't work then use the command: brew link libpq --force.
Also put in your .zshrc file the following export PATH="/usr/local/opt/libpq/bin:$PATH". This creates all the necessary linkages for libpq library .
Now restart the terminal or use the following command source ~/.zshrc.
Now use the command pip install psycopg2. It will work.
This works, even when you are working in conda environment.
N.B. pip install psycopg2-binaryshould be avoided because as per the developers of the psycopg2 library
The use of the -binary packages in production is discouraged because in the past they proved unreliable in multithread environments. This might have been fixed in more recent versions but I have never managed to reproduce the failure.
Try with these:
virtualenv -p /usr/bin/python3 test_env
source test_env/bin/activate
pip install psycopg2
run python and try to import if you insist on installing it on your systems python try:
pip3 install psycopg2
Recently faced this issue on my production server. I had installed pyscopg2 using
sudo pip install psycopg2
It worked beautifully on my local, but had me for a run on my ec2 server.
sudo python -m pip install psycopg2
The above command worked for me there. Posting here just in case it would help someone in future.
sudo pip install psycopg2-binary
You need to install the psycopg2 module.
On CentOS:
Make sure Python 2.7+ is installed. If not, follow these instructions: http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/
# Python 2.7.6:
$ wget http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
$ tar xf Python-2.7.6.tar.xz
$ cd Python-2.7.6
$ ./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
$ make && make altinstall
$ yum install postgresql-libs
# First get the setup script for Setuptools:
$ wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
# Then install it for Python 2.7 and/or Python 3.3:
$ python2.7 ez_setup.py
$ easy_install-2.7 psycopg2
Even though this is a CentOS question, here are the instructions for Ubuntu:
$ sudo apt-get install python3-pip python-distribute python-dev
$ easy_install psycopg2
Cite: http://initd.org/psycopg/install/
For python3 on ubuntu, this worked for me:
$sudo apt-get update
$sudo apt-get install libpq-dev
$sudo pip3 install psycopg2-binary
i have the same problem, but this piece of snippet alone solved my problem.
pip install psycopg2
Run into the same issue when I switch to Ubuntu from Windows 10.. the following worked for me.. this after googling and trying numerous suggestions for 2 hours...
sudo apt-get install libpq-dev
then
pip3 install psycopg2
I hope this helps someone who has encountered the same problem especially when switching for windows OS to Linux(Ubuntu).
I have done 2 things to solve this issue:
use Python 3.6 instead of 3.8.
change Django version to 2.2 (may be working with some higher but I change to 2.2)
For Python3
Step 1: Install Dependencies
sudo apt-get install python3 python-dev python3-dev
Step 2: Install
pip install psycopg2
check correctly if you had ON your virtual env of your peoject, if it's OFF then make it ON. execute following cammands:
workon <your_env_name>
python manage.py runserver
It's working for me
It's very simple, not sure why nobody mentioned this for mac before.
brew install postgresql
pip3 install psycopg2
In simple terms, psycopg2 wants us to install postgres first.
PS: Don't forget to upvote, so that it can help other people as well.
Solved the issue with below solution :
Basically the issue due to _bz2.cpython-36m-x86_64-linux-gnu.so Linux package file. Try to find the the location.
Check the install python location ( which python3)- Example: /usr/local/bin/python3
copy the file under INSTALL_LOCATION/lib/python3.6
cp -rvp /usr/lib64/python3.6/lib-dynload/_bz2.cpython-36m-x86_64-linux-gnu.so /usr/local/lib/python3.6
try:
pip install psycopg2 --force-reinstall --no-cache-dir
Python2 importerror no module named psycopg2
pip install psycopg2-binary
Requirement already satisfied...
Solved by following steps:
sudo curl https://bootstrap.pypa.io/pip/2.7/get-pip.py -o get-pip.py
sudo python get-pip.py
sudo python -m pip install psycopg2-binary
pip install psycopg-binary
The line above helped me
For Python3 use this:
sudo apt-get install -y python3-psycopg2