jupyter notebook - ImportError: No module named 'bson' - python

Trying to play with some jupyter notebook, I have an issue with the bson module which seams not available as reported in the error: "ImportError: No module named 'bson'"
I'm running jupyter notebook 4.3.0 over a python 2.7 kernel which is available in a dedicated virtual environment. I tried to install manually the bson module through a simple "conda install bson" but it's not in the official/standard repo so I had to install OpenMDAO/bson. Finally, it didn't change the issue. I understand that the module might come from the pymongo package so I tried to install with the same result.
Any hint here? What's the link between bson and pymongo?

You can advise this answer: import error: no module named bson
Which states that:
If you don't get the no module named bson error but the EPOCH_AWARE import error, this is due to a name clash between bson and pymongo.
In this case, you should do these in order:
sudo pip uninstall bson
sudo pip uninstall pymongo
sudo pip install pymongo
In your case, try to start with a fresh virtualenv and do the above mentioned in the given order
That also answers the link between bson and pymongo.

Related

Python imports aren't installing / can't be found

Firstly, I'm super new to Python/code and stackoverflow, so apologies if I sound like a child trying to explain complex rocket science.
I'm following a tutorial on creating a fake teachers database, and they say
import mysql.connector
from mysql.connector import Error
import panda
however, when I go to import, I get an error of
ImportError: Unable to import required dependencies:
pytz: No module named 'pytz'
dateutil: No module named 'dateutil'
Despite the modules being imported and in the Python folder. It took me around 30 minutes to get MySQL imported, and honestly I'm not even really sure how it fixed. I renamed the folder, I copied the folder into the virtual environment I'm using (which I'm not even sure how to not use that, it seems to just create difficulties in doing any importing), I had to reinstall pip multiple times as it also error'd the first 2 tries. I'm really confused and a little frustrated as I have zero idea how to fix this, or what even the errors are in the first place.
Any help would be much appreciated!!
Pip should be included with your Python installation. Try pip install mysql and pip install panda. If that doesn't work try py -m pip install mysql and py -m pip install panda.
Try:
pip3 install mysql pytz
You can install multiple packages at the same time!
If you want to get out of the virtual environment you created you can use the deactivate command.
See If pip is installed in your system
If its Installed , Install pytz by exeuting
pip install pytz
Install Pip = https://bootstrap.pypa.io/get-pip.py
Just download and run this file

Cannot import mysql.connector - ModuleNotFoundError: No module named 'mysql'

import mysql.connector got the following error.
import mysql.connector
ModuleNotFoundError: No module named 'mysql'
However, the following commands show the mysql is installed?
(env) bash-4.2$ pip list | grep mysql
mysql (0.0.3)
mysqlclient (2.0.3)
(env) bash-4.2$ conda list mysql
WARNING conda.core.prefix_data:_load_site_packages(272): Problem reading non-conda package record at lib/python3.6/site-packages/pyzmq-17.0.0-py3.6.egg-info/PKG-INFO. Please verify that you still need this, and if so, that this is still installed correctly. Reinstalling this package may help.
WARNING conda.core.prefix_data:_load_site_packages(272): Problem reading non-conda package record at lib/python3.6/site-packages/jupyterlab-2.3.1-py3.9.egg-info/PKG-INFO. Please verify that you still need this, and if so, that this is still installed correctly. Reinstalling this package may help.
WARNING conda.core.prefix_data:_load_site_packages(272): Problem reading non-conda package record at lib/python3.6/site-packages/conda-4.10.3-py3.6.egg-info/PKG-INFO. Please verify that you still need this, and if so, that this is still installed correctly. Reinstalling this package may help.
WARNING conda.core.prefix_data:_load_site_packages(272): Problem reading non-conda package record at lib/python3.6/site-packages/certifi-2021.5.30-py3.6.egg-info/PKG-INFO. Please verify that you still need this, and if so, that this is still installed correctly. Reinstalling this package may help.
# packages in environment at /apps/external/4/anaconda3:
#
# Name Version Build Channel
mysql 5.7.20 h55eaa98_0 https://mycompany.intranet/repository/anaconda-main-proxy
BTW, why the version of pip mysql is so low? (0.0.3)
pip install mysql-connector
or
Do not make your .py file name: mysql.py or something like that.
OS: Mac 11.6.2 (Big Sur)
Python: 3.9.7
If you, like me, use conda environments, and you have trouble installing the mysql-connector-python module with an existing mysql module installed, try this:
(env)username ~% conda update --all
(env)username ~% conda uninstall mysql
(env)username ~% conda install -c conda-forge mysql
(env)username ~% conda install -c conda-forge mysql-connector-python
Now the mysql.connector package is found from the JupyterLab notebook when running it from either VSCode or from Anaconda Navigator.
I hope this is useful for someone.

ImportError: No module named 'graphframes' databricks

I am trying to import graphframes in to my databricks notebook
from graphframes import *
but failed with following error message
ImportError: No module named 'graphframes'
How can I add/import in to databricks notebook, any help appreciated.
Note: By default, "graphframes" is not installed on the databricks.
You need to install the package explicitly.
You can install the packages in different methods.
Method1: Installing external packages using pip cmdlet.
Syntax: %sh /databricks/python3/bin/pip install <packagename>
%sh
/databricks/python3/bin/pip install graphframes
Method2: Using Databricks library utilities
Syntax:
dbutils.library.installPyPI("pypipackage", version="version", repo="repo", extras="extras")
dbutils.library.restartPython() # Removes Python state, but some libraries might not work without calling this function
To install graphframes using databricks library utilities use the below command.
dbutils.library.installPyPI("graphframes")
Tried the examples available in this article GraphFrames Documentation.
Notebook output:
Hope this helps.
graphframes is not default dependency with python. You should install this dependency.
You need to install the graphframes module by opening your terminal and typing pip install graphframes

pip list shows installed module but still getting import error

I am working with python flask's requests module. I have installed requests module using :
pip install requests
And verified that requests module exists when I run :
pip list
But when I run my python application , I receive import Error for requests module.
I noticed that pip is installing the module in C:\Users\xx\Documents\Projects\Python\Python3REST\lib\site-packages\ folder BUT the interpreter is looking for the module in C:\Users\xx\Documents\Projects\Python\Python3REST\lib\site-packages\flask\ folder.
I have tried running the command :
pip install --install-option="Path to install in" requests
But threw some other error.
The import error I am getting states :
ImportError: cannot import name 'requests' from 'flask'
(C:\Users\xx\Documents\Projects\Python\Python3REST\lib\site-packages\flask\__init__.py)
I am working in virtualenv in Windows 10.
I recently had the same problem installing a self made package. I installed it with pip install <package> and checked it was actually installed with pip list but running the script with import <package> returned a ModuleNotFoundError: No module named <package>.
I solved the problem creating an empty file called __init__.py in the package directory.
Check https://pythontips.com/2013/07/28/what-is-init-py/ and https://docs.python.org/3/tutorial/modules.html#packages for better understanding.
what if you add that folder to your path? using sys.path.extend?
I solved it using python3 -m pip install <package name>. In the OP's case, it should be python3 -m pip install requests.
Note that I'm using python 3.10.

ImportError: No Module named picklefield.fields (Yep pip install says it is there)

I am using vagrant to run my python environment. In my data models I am using django-picklefield module.
when I run my server it says
ImportError: No module named picklefield.fields.
I tried to uninstall and install the picklefield module. Still having the same problem.
You should be able install via:
/[your python install directory]/bin/pip install django-picklefield
If you do this directly instead of a general pip call to install django-picklefield, that will ensure that it is installed on the correct version of Python.
Based on your description my best guess is that you have multiple versions of Python installed, and that your install/uninstall is happening on the wrong one.

Categories

Resources