Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no module named 'text_recognizer' #7

Open
bwanaaa opened this issue May 27, 2019 · 14 comments
Open

no module named 'text_recognizer' #7

bwanaaa opened this issue May 27, 2019 · 14 comments

Comments

@bwanaaa
Copy link

bwanaaa commented May 27, 2019

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

@switchfootsid
Copy link

Same issue.

@kshitizrimal
Copy link

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

@Franceshe
Copy link

Same issue here

@Franceshe
Copy link

Franceshe commented Jan 19, 2020

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

@sebastian-sosa
Copy link

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

@callezenwaka
Copy link

callezenwaka commented Apr 14, 2020

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

@goopyflux
Copy link

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.

@letsgo247
Copy link

@sebastian-sosa Thanks! It works!

@Haaarrrssshhh
Copy link

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

@MuhammadUmarFarooq786
Copy link

MuhammadUmarFarooq786 commented Mar 11, 2021

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!

@pipegalera
Copy link

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.

@InHouse-Banana
Copy link

InHouse-Banana commented May 18, 2023

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.

@Luismbpr
Copy link

Luismbpr commented Nov 7, 2023

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

@byvuong
Copy link

byvuong commented Sep 3, 2024

Had issue running the code. Hope this help.

# Download bootstrap.py 
!wget --quiet https://gist.githubusercontent.com/charlesfrye/f73b5fbcb3a662df8fbd58e1a488a105/raw/5b588a0500c598f0893a39371d890b1bd8d3b0a1/bootstrap.py -O bootstrap.py 

# Download files 
import bootstrap 

# Set path 
import sys 
sys.path.append('/content/fsdl-text-recognizer-2022-labs') 
print('paths: ', sys.path) 

 
# Verify path 
import os 
print(os.path.exists('requirements/prod.in')) 

# Downgrade pip for old packages
!pip install pip==23.3.1 

# Install packages without wandb 
!pip install -r requirements/prod.in 

# Install wandb 
!pip install wandb 

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests