fsdl-text-recognizer-project icon indicating copy to clipboard operation
fsdl-text-recognizer-project copied to clipboard

no module named 'text_recognizer'

Open bwanaaa opened this issue 6 years ago • 14 comments
trafficstars

from the lab2_sln directory I entered $python text_recognizer/datasets/emnist_dataset.py and got

fsdl-text-recognizer-project/lab2_sln$ python text_recognizer/dataset/emnist_dataset.pyTraceback (most recent call last):
  File "text_recognizer/datasets/emnist_dataset.py", line 16, in <module>
    from text_recognizer.datasets.dataset import _download_raw_dataset, Dataset, _parse_args
ModuleNotFoundError: No module named 'text_recognizer'

The emnist_dataset.py script DOES have this line

from text_recognizer.datasets.dataset import _download_raw_dataset, Dataset, _parse_args

and the dataset.py script has this line in it: from text_recognizer import util

There is however NO text_recognizer.py script. However there is a text_recognizer directory with the lab2_sln directory

bwanaaa avatar May 27 '19 04:05 bwanaaa

Same issue.

switchfootsid avatar Jun 01 '19 16:06 switchfootsid

its the problem with the PYTHONPATH environment variable..

use this code on the file you want to run from the sub directories

import os, sys,inspect

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)

sys.path.insert(0,parentdir)

its basically setting the environment path value to that of the parent directory

kshitizrimal avatar Aug 02 '19 05:08 kshitizrimal

Same issue here

Franceshe avatar Jan 19 '20 23:01 Franceshe

its the problem with the PYTHONPATH environment variable..

use this code on the file you want to run from the sub directories

import os, sys,inspect

currentdir = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
parentdir = os.path.dirname(currentdir)

sys.path.insert(0,parentdir)

its basically setting the environment path value to that of the parent directory

Hi, i am a bit confused by the solution, are you refering adding the code to emnist_dataset.py? If my desired execution file is: /SP2020/fsdl-text-recognizer-project-master/lab1/text_recognizer/datasets/emnist_dataset.py

Franceshe avatar Jan 19 '20 23:01 Franceshe

Hello, I had the same issue and following this answer, what helped me was to add the following code to the top of emnist_dataset.py:

import sys
sys.path.append('/home/path-to-project/fsdl-text-recognizer-project/lab1')
print('paths: ', sys.path)

Note the first last on the output of executing the script:

paths:
['/home/path-to-project/fsdl-text-recognizer-project/lab1/text_recognizer/datasets', 
'/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/home/sebastian/.local/share/virtualenvs/fsdl-text-recognizer-project-wznZWvdb/lib/python3.6/site-packages',
'/home/sebastian/repos/fsdl-text-recognizer-project/lab1', '/home/path-to-project/fsdl-text-recognizer-project/lab1']

For some reason, only the folder home/path-to-project/fsdl-text-recognizer-project/lab1/text_recognizer/datasets was included on the python paths, but not the one ending in lab1

sebastian-sosa avatar Mar 26 '20 22:03 sebastian-sosa

Your solution worked for me @sebastian-sosa Thanks a lot.

callezenwaka avatar Apr 14 '20 07:04 callezenwaka

I'm running the code locally (not on GCP) and I had the same issue. Then I found these instructions in the setup.md file under the instructions for running on GCP (which I had previously ignored, since I was running locally)

Also, run export PYTHONPATH=. before executing any commands later on, or you will get errors like ModuleNotFoundError: No module named 'text_recognizer'.

In order to not have to set PYTHONPATH in every terminal you open, just add that line as the last line of the ~/.bashrc file using a text editor of your choice (e.g. nano ~/.bashrc)

This solved my issue FWIW.

goopyflux avatar Jun 03 '20 14:06 goopyflux

@sebastian-sosa Thanks! It works!

letsgo247 avatar Aug 09 '20 15:08 letsgo247

Hello, I had the same issue and following this answer, what helped me was to add the following code to the top of emnist_dataset.py:

import sys
sys.path.append('/home/path-to-project/fsdl-text-recognizer-project/lab1')
print('paths: ', sys.path)

Note the first last on the output of executing the script:

paths:
['/home/path-to-project/fsdl-text-recognizer-project/lab1/text_recognizer/datasets', 
'/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/home/sebastian/.local/share/virtualenvs/fsdl-text-recognizer-project-wznZWvdb/lib/python3.6/site-packages',
'/home/sebastian/repos/fsdl-text-recognizer-project/lab1', '/home/path-to-project/fsdl-text-recognizer-project/lab1']

For some reason, only the folder home/path-to-project/fsdl-text-recognizer-project/lab1/text_recognizer/datasets was included on the python paths, but not the one ending in lab1

Had a similar issue , worked for me too. Thank you

Haaarrrssshhh avatar Dec 08 '20 16:12 Haaarrrssshhh

Hello, I had the same issue and following this answer, what helped me was to add the following code to the top of emnist_dataset.py:

import sys
sys.path.append('/home/path-to-project/fsdl-text-recognizer-project/lab1')
print('paths: ', sys.path)

Note the first last on the output of executing the script:

paths:
['/home/path-to-project/fsdl-text-recognizer-project/lab1/text_recognizer/datasets', 
'/usr/lib/python36.zip',
'/usr/lib/python3.6',
'/usr/lib/python3.6/lib-dynload',
'/home/sebastian/.local/share/virtualenvs/fsdl-text-recognizer-project-wznZWvdb/lib/python3.6/site-packages',
'/home/sebastian/repos/fsdl-text-recognizer-project/lab1', '/home/path-to-project/fsdl-text-recognizer-project/lab1']

For some reason, only the folder home/path-to-project/fsdl-text-recognizer-project/lab1/text_recognizer/datasets was included on the python paths, but not the one ending in lab1

@sebastian-sosa Thanks it worked!

MuhammadUmarFarooq786 avatar Mar 11 '21 09:03 MuhammadUmarFarooq786

I'm running the code locally (not on GCP) and I had the same issue. Then I found these instructions in the setup.md file under the instructions for running on GCP (which I had previously ignored, since I was running locally)

Also, run export PYTHONPATH=. before executing any commands later on, or you will get errors like ModuleNotFoundError: No module named 'text_recognizer'.

In order to not have to set PYTHONPATH in every terminal you open, just add that line as the last line of the ~/.bashrc file using a text editor of your choice (e.g. nano ~/.bashrc)

This solved my issue FWIW.

Any way to replicate in a Windows 10 machine?

set PYTHONPATH=. doesn't do the trick sadly.

pipegalera avatar May 23 '22 11:05 pipegalera

import sys sys.path.append('/home/path-to-project/fsdl-text-recognizer-project/lab1') print('paths: ', sys.path)

I think this is a good solution as the text_recognizer library might be updated from lab to lab. Hence adding /home/path-to-project/fsdl-text-recognizer-project/lab1 to the Pythonpath might end in a conflict where different versions are loaded if more labs are included .../lab2, .../lab3, etc... etc... Probably the last one added to .bashrc will be the imported one, I'm not sure though.

InHouse-Banana avatar May 18 '23 13:05 InHouse-Banana

Hello. I am having this issue on Google Colab and do not really understand how to select the path so Colab can use this. Is there a clearer instruction I can follow along? So far I opened lab02a_lightning.ipynb

Here are so far the two solved issues I was having:

!pip install pytorch_lightning ### Added
!pip install torchtext ### Added

import pytorch_lightning as pl

version = pl.__version__

docs_url = f"https://pytorch-lightning.readthedocs.io/en/{version}/"  # version can also be latest, stable
docs_url

The other one with "No module named 'text_recognizer' was solved this by using %cd instead of !cd as I was used to on Jupyter Notebooks.

%ls
%cd '/content/fsdl-text-recognizer-2022-labs/lab02'
from text_recognizer.lit_models import BaseLitModel

Luismbpr avatar Nov 07 '23 20:11 Luismbpr