the-full-stack / fsdl-text-recognizer-project

Lab materials for the Full Stack Deep Learning Course
https://fullstackdeeplearning.com/course
1.21k stars 428 forks source link

no module named 'text_recognizer' #7

Open bwanaaa opened 5 years ago

bwanaaa commented 5 years ago

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 commented 5 years ago

Same issue.

kshitizrimal commented 5 years ago

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 commented 4 years ago

Same issue here

Franceshe commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

goopyflux commented 4 years ago

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 commented 4 years ago

@sebastian-sosa Thanks! It works!

Haaarrrssshhh commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 2 months ago

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)