Python - Notion API - Can't import module - python

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!

Related

Need to install Python Pint Package using MSYS

I am very new to using MSYS and I need it to run a Fortran based code through python interface. I followed the whole installation procedure in this link
https://github.com/SINTEF/thermopack/blob/main/addon/pycThermopack/README.md
and when I tried to install Python Pint package I kept getting this error:
MSYS Error
It seems that this package is very important to run the GUI correctly. What did I miss here? Is there any other way to install this package?
Thanks a lot in advance.
Solution
I managed to install it by installing Pip command using
$ pacman -S python3-pip
$ pip3 install --upgrade pip
pip install Pint

No module named 'fbchat'

So im new at python and programming and trying to work out the basic of fbchat which seems very manageable but I keep getting this error: ModuleNotFoundError: No module named 'fbchat' I'm 100% sure that I've installed fbchat by using:
pip install fbchat
and have also tried
git clone https://github.com/carpedm20/fbchat.git
pip install fbchat
Either way I still get the same error.
This is the code:
import fbchat
session = fbchat.Session.login("<xxxxxx#hotmail.com>", "<xxxx>")
print("Own id: {}".format(session.user.id))
session.user.send_text("Hi You!")
session.logout()
I really hope that you can help me with this problem, thank you for your time
First check your pip version is using desired python or not
pip --version
If not then you should use different pip version for an example if you're using python3 then install using pip3
If there's no issue of version then try to use virtual environment
create one using
python -m venv venv
source venv/bin/activate
pip install fbchat
Refer this link for os wise instructions
https://packaging.python.org/guides/installing-using-pip-and-virtual-environments/
Install using Python3.8 -m pip install fbchat

Why is a package I have installed not getting recognised

I have installed a package named hypixel for my discord bot using pip install hypixel. It finished installing without any errors. At the top of my script I have import hypixel. But when I try and run it I get this error:
File "D:\Documents\Discord Bot\Addicts Discord Bot\bot.py", line 1, in <module>
import hypixel
ModuleNotFoundError: No module named 'hypixel'
I am not sure if this is too relevant but my pip isn't the latest version and I get an error when I try and update it.
Edit: I have now successfully updated my pip. But even when I try and reinstall the package it still won't work.
Instead of using pip install python, use pip install hypixel. Then try to import it in your code using import hypixel.
In your question you say you used pip install python, did you mean to say pip install hypixel?
Also if you use python3 but have python3 installed make sure you use pip3.
You can install this with sudo apt-get install python3-pip (assuming you use a debian based distro). Then use sudo pip3 install hypixel
Edit:
For windows installation follow this link

ImportError: No module named 'ldap' Python 3.5

I'm running Python 3.5 (on Windows) and I have installed python-ldap from https://pypi.python.org/pypi/python-ldap/
I also tried using ldap3 but I keep getting an error saying
"ImportError: No module named 'ldap'
I looked around and saw some people saying there's no python-ldap for 3.5 so I installed 2.6 still getting the same error.
Is there a way to import ldap and make it work for Python 3.5?
Try the command below:
sudo apt-get install libsasl2-dev python-dev libldap2-dev libssl-dev
sudo pip3 install pyldap
Open a command line(cmd, powershell, git bash)
Check you python version
$ pyhton --version
Go to https://www.lfd.uci.edu/~gohlke/pythonlibs/
Download the library according with your python version and windows system
And install it on a command line using
pip install file_downloaded.whl
For example:
If you have python 3.5x and windows x64,
download the file python_ldap‑3.2.0‑cp35‑cp35m‑win_amd64.whl
pip install python_ldap‑3.2.0‑cp35‑cp35m‑win_amd64.whl
I'm running Apache Airflow on an Amazon EC2-Instance and I was getting "ImportError: No module named 'ldap3'. I used these two sites https://www.python-ldap.org/en/latest/installing.html and http://ldap3.readthedocs.io/installation.html to run the commands sudo python -m pip install python-ldap and sudo pip install ldap3 but my pip wasn't working for the last command so after some investigation I found out in my /usr/bin/ directory I had pip, pip-2.7, pip-3.6, and pip-python so I changed the command to pip-3.6 install ldap3 and then everything worked! Hope this helps someone.
I tried multiple approaches but finally, PyPI official documentation fixed this.
I was trying to execute on VS Code and did pip3 install python-ldap, but it didn't solve the issue. So I did the below from VS Code
# %% - This runs the below code as a Jupyter notebook cell
!pip3 install python-ldap
Now, I am able to import ldap and use it
Inside you folder, you can use virtualenv for python 3, example:
/opt/python-ldap-test
virtualenv -p /usr/bin/python3.5 venv
source venv/bin/activate
and then
pip install ldap3
It's extremely complicated to make things from 2.X to work in 3.X. Have you tried using it in a separate, 2.X only script and using it from there? It's not so unusual to combine python 2.X with 3.X in that manner or so I've heard.

ImportError: No module named 'pymongo'

I have a problem running pymongo on Win 7 (64) with Python 3.4, mongodb 4.2.10.
The error output is as follows:
import pymongo
ImportError: No module named 'pymongo'
The code is pretty simple:
import pymongo
from pymongo import MongoClient
client=MongoClient()
db=client.test_db
dict={'A':[1,2,3,4,5,6]}
db.test_collection.insert(dict)
to_print=db.test_collection.find()
print(to_print)
I tried already re-installing Python and MongoDB - did not help. It works when I do it manually in cmd, i.e. mongod.exe and mongo.exe work fine. It appears there is problem with pymongo, but I don't know how to fix it.
All you need is to actually install pymongo (currently you just have mongo and python, but they do not know how to speak with each other). This page is telling you exactly what to do:
go to pymongo page
download and run installer.
I am new to Python,
But I think install setuptools is a good idea,
after that:
pip install pymongo
If you have installed pymongo using following command :
sudo pip install pymongo or
sudo -E pip install pymongo
And still you are getting import error then try to run your python script with sudo like :
sudo python example.py
If you are able to run the script this way, but not without sudo.
Then there can be a problem with PYTHON_PATH or Permission issue.
Solving isssue#1 (i.e. PYTHON_PATH) :
Location where pip installs packages and location where python looks for packages do not match.
So how do you find where pip install packages ? Run following command :
sudo pip show pymongo
It shows output like this :
---
Name: pymongo
Version: 3.4.0
Location: /usr/local/lib/python2.7/dist-packages
Now you know where pip install packages. Add following line in your .bashrc :
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/dist-packages/
Run following command to execute .bashrc again :
source .bashrc
Now try to run python script without sudo. It should run.
If not then do the following :
Solving issue#2 (i.e. Permission):
Allow non-root users to read and execute python pacakages.
sudo chmod -R ugo+rX /usr/local/lib/python2.7/
This should solve your all problems. You should be able to run python script without sudo.
I was working on Python 3 but installed the Python 2 version of pymongo with
$ pip install pymongo command. I uninstalled this version of pymongo with
$ pip uninstall pymongo and installed Python 3 version of it via
$ pip3 install pymongo. (after installing pip3 via $ sudo-apt install pip3 in linux terminal). I hope this solves your problem as well as mine.
Try this:
sudo apt-get install python-pip
sudo pip install pymongo
If you have a problem like that probably you didn't two things.
you didn't install pymongo.You can install by below command;
$pip install pymongo
You installed pymongo but You have two python packages location. like below;
C:\Python\Python37-32\Lib\site-packages\pymongo (pymongo installed here)
C:\Anaconda3\Lib\site-packages\ "pymongo is not here"
And you try to work here.
Probably you run Spyder but Spyder is looking to Anaconda\Lib\site-packages\ but pymongo packages are not here.
Sorry for bad english.
For me i am running Flask server so i had to go to the terminal and run the command :
pip install Flask-PyMongo
Make a new folder in your documents like "flask-pymongo"
In your terminal change directory to C:\Users\YOUR_USERNAME\Documents\Flask-PyMongo\
git clone https://github.com/dcrosta/flask-pymongo
cd flask-pymongo
py setup.py develop OR python setup.py develop (depends how python was install to your path)
from anywhere in your terminal use : pip install pymongo
Solution is for windows users
Try the following:
conda install pymongo
For me I had this error after I'd installed pymongo via console/terminal but when I looked in my project's interpreter (for example in PyCharm you go to
Preferences > 'Project: <'name of your project'>' > Project Interpreter
I saw things like pip and setuptools but not pymongo. I clicked the '+' at the bottom of the pane and searched for pymongo and found it and could install it there. After adding this the project ran fine
I had the same error on linux while working on some project,I'll post for you the linux commands for it and you can find the windows equivalent easily
what solved my problem is to first install virtual environment venv
> sudo pacman -S python-virtualenv
create a venv (it's in best practice to keep virtualenv in different dir than the project since you don't need to distribute it) and activate it.
> python -m venv venv/
> . venv/bin/activate
once you are in the venv you should see the command prompt like this one
(venv) [sam#archlinux labs]$
now install pymongo inside your venv using
(venv) [sam#archlinux labs]$ pip install pymongo
then run your files while the virtual environment is active
(venv) [sam#archlinux labs]$ python myfile.py
to install flask also the same inside your venv using
(venv) [sam#archlinux labs]$ pip install flask
I'm working with Python's virtual environment (venv) and for some reason it didn't work for me to just
pip install pymongo
in my venv. It installed the package correctly in venv/Lib/site-packages put I couldn't run the script.
What worked for me was to create a requirements.txt file and write the packages I needed for the project in there
pymongo==4.0.1
and then run the command
python3 -m pip install -r requirements.txt
I can now run my script. Hope this can help any newcomers to this question.
Whenever I've got an issue as this, I open a new terminal and cd into the directory of my project. Do not activate your virtualenv yet. Now, install the missing module, activate your virtualenv, case closed.

Categories

Resources