Jupyter Notebook - ModuleNotFoundError when import selfmade module - jupyter

I can't import any of my selfmade moduls into my jupyter-notebook script.
Pip installed modules like numpy or pandas work.
when calling os.listdir() for my current work directory, the modules are shown.
The current work directory also appears in my sys.path

Related

empty __init__.py file with error " ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' " when importing torchvision on M1

I have a functioning PyTorch installation with a conda environment with MPS backend working fine on a M1 mac.
However, after installing torchvision, when I try to import torchvision, I get this error (also shown in screenshot):
ImportError: cannot import name 'PILLOW_VERSION' from 'PIL' (/opt/anaconda3/lib/python3.9/site-packages/PIL/__init__.py)
In the screenshot below, I run python in my terminal and then try to import torchvision and get the error.
I have navigated to and opened the file in question __init__.pyin the PIL folder, and the file itself is empty.
If relevant:
torch version is 1.13.0.dev20220911
Python is 3.9.13
Conda is 22.9.0
I have tried installing and reinstalling with conda and pip multiple times but with the same result when importing torchvision.
I found this stackoverflow question about PILLOW_version, which got me to try to rename the __init__.py file that turned out to be empty, which I did not expect, since that made it impossible to rename the pillow versioning.
Thanks in advance.

Python Cannot Find Module Located in Sub-Directory when Importing QAxContainer from PyQt5

Python appears to be unable to locate the module QAxContainer in PyQt5. The package was installed using Conda and is present in a sub-directory of PyQt5 but cannot be located. Additional testing with pip resulted in the same error.
Ubuntu 20.04
Python 3.8.5
conda list
pyqt5 5.15.2 pypi_0 pypi
from PyQt5 import QAxContainer
ImportError: cannot import name 'QAxContainer' from 'PyQt5' (/home/brian/anaconda3/lib/python3.8/site-packages/PyQt5/init.py)
However, qaxcontainer.py is present in /home/brian/anaconda3/lib/python3.8/site-packages/PyQt5/uic/widget-plugins
There should be QAxContainer.pyd and QAxContainer.pyi at /home/brian/anaconda3/lib/python3.8/site-packages/PyQt5/. If you dont have them maybe there's a problem with the package, try reinstalling PyQt5.
According to antonio2924, QAxContainer.pyd and QAxContainer.pyi should be located at /home/brian/anaconda3/lib/python3.8/site-packages/PyQt5/. The .pyd file extension is specific to Windows. Furthermore:
The QAxContainer module is a Windows-only extension for accessing
ActiveX controls and COM objects. See, https://doc.qt.io/qt-5/qaxcontainer-module.html
I am running Ubuntu 20.04, which explains why QAxContainer is not being installed.

How to execute the right Python to import the installed tensorflow.transform package?

The version of my Python is 2.7.13.
I run the following in Jupyter Notebook.
Firstly, I installed the packages
%%bash
pip uninstall -y google-cloud-dataflow
pip install --upgrade --force tensorflow_transform==0.15.0 apache-beam[gcp]
Then,
%%bash
pip freeze | grep -e 'flow\|beam'
I can see that the package tensorflow-transform is installed.
apache-beam==2.19.0
tensorflow==2.1.0
tensorflow-datasets==1.2.0
tensorflow-estimator==2.1.0
tensorflow-hub==0.6.0
tensorflow-io==0.8.1
tensorflow-metadata==0.15.2
tensorflow-probability==0.8.0
tensorflow-serving-api==2.1.0
tensorflow-transform==0.15.0
However when I tried to import it, there are warning and error.
WARNING:tensorflow:From /usr/local/lib/python2.7/dist-packages/tensorflow_estimator/python/estimator/api/_v1/estimator/__init__.py:12: The name tf.estimator.inputs is deprecated. Please use tf.compat.v1.estimator.inputs instead.
ImportErrorTraceback (most recent call last)
<ipython-input-3-26a4792d0a76> in <module>()
1 import tensorflow as tf
----> 2 import tensorflow_transform as tft
3 import shutil
4 print(tf.__version__)
ImportError: No module named tensorflow_transform
After some investigation, I think I have some ideas of the problem.
I run this:
%%bash
pip show tensorflow_transform| grep Location
This is the output
Location: /home/jupyter/.local/lib/python3.5/site-packages
I tried to modify the $PATH by adding /home/jupyter/.local/lib/python3.5/site-packages to the beginning of $PATH. However, I still failed to import tensorflow_transform.
Based on the above and the following information, I think, when I ran the import command, it executes Python 2.7, not Python 3.5
import sys
print('\n'.join(sys.path))
/usr/lib/python2.7
/usr/lib/python2.7/plat-x86_64-linux-gnu
/usr/lib/python2.7/lib-tk
/usr/lib/python2.7/lib-old
/usr/lib/python2.7/lib-dynload
/usr/local/lib/python2.7/dist-packages
/usr/lib/python2.7/dist-packages
/usr/local/lib/python2.7/dist-packages/IPython/extensions
/home/jupyter/.ipython
Also,
import sys
sys.executable
'/usr/bin/python2'
I think the problem is tensorflow_transform package was installed in /home/jupyter/.local/lib/python3.5/site-packages. But when I run "Import", it goes to /usr/local/lib/python2.7/dist-packages to search for the package, rather than /home/jupyter/.local/lib/python3.5/site-packages, so even updating $PATH does not help. Am I right?
I tried to upgrade my python, but
%%bash
pip install upgrade python
Defaulting to user installation because normal site-packages is not writeable
Then, I added --user. It seems that the python is not really upgraded.
%%bash
pip install --user upgrade python
%%bash
python -V
Python 2.7.13
Any solution?
It seems to me that your jupyter notebook is not using the right python environment.
Perhaps, you installed the package under version 3.5,
but the Notebook uses the other one, thus it cannot find the library
You can pick the other interpreter by clicking on: Python(your version) - bottom left.
VS-Code - Select Python Environment 1
However you can do this also via:
CNTRL+SHIFT+P > Select Python Interpreter to start Jupyter Server
If that does not work make sure that the package you are trying to import is installed under the correct python environment.
If not open up a terminal, activate the environment and install it using:
pip install packagename
For example i did the same thing here: (Note: I'm using Anaconda)
installing tensorflow_transform
After a installation, you can import it in your code directly like this:
importing tensorflow_transform

ImportError: No module named pytesseract on Jupiter lab and VSCode but not my local

I have tried running a ProcessImage.py file in which I import the package pytesseract in Jupiter Lab and VSCode.
This is the error that pops out :
import pytesseract
ImportError: No module named pytesseract
I already know that pytesseract is installed in my environment because with conda list:
pytesseract 0.3.2 py_0 conda-forge
pytest 5.3.5 py38_0 coda-forge
However, if I run my ProcessImage.py file on my local no error is prompted.
I know the error is related to paths in Jupiter Lab and VsCode but I can't seem to find a solution.
Have you tried to launch your python file using Ctrl+F5 command for run?
I had this same ImportError when trying to launch my python program using the .run extension. It persistently started python 2.7 while my environment was using Python3. I first thought that it was a VS code error but it wasn't.

Import local module to the Jupyter Notebook

I've a local function to transform my data on a local.
For example, when I tried to import:
import com.company.area.project.area.functions
I've received the error:
console: 49: error: object company is not a member of package com
import com.company.area.project.area.functions
I'm using Anaconda and the pip. Reading trough the web I've found this question: Is there a pip / easy_install for Scala?
So, I noticed that there is no a equivalent to "Pip install ." we have in python.
So, the question is. How can I import a custom function in my Jupyter Notebook?
First you have to ensure that you have Scala environment enabled for your jupyter notebook.
pixiedust can help you with installing scala packages in your jupyter notebook.
A specific example in your case will be to deploy your project as a jar file to a repository or an address where you can then pass to the pixiedust package
Code example should look like this:
import pixiedust
pixiedust.installPackage("https://github.com/companyrepo/jars/raw/master/dist/functions-assembly-1.0.jar")