Python files work fine when executed from another directory

I have a very strange problem. When I run the file from another directory, it works fine. but another wise i get this error

from textprocessor import * File "/home/mohit/Documents/analysis/categorization/textprocessor.py", line 2, in <module> import nltk File "/usr/local/lib/python2.7/dist-packages/nltk/__init__.py", line 101, in <module> import ccg File "/usr/local/lib/python2.7/dist-packages/nltk/ccg/__init__.py", line 15, in <module> from chart import * File "/usr/local/lib/python2.7/dist-packages/nltk/ccg/chart.py", line 33, in <module> from nltk.parse.api import * File "/usr/local/lib/python2.7/dist-packages/nltk/parse/__init__.py", line 46, in <module> from featurechart import * File "/usr/local/lib/python2.7/dist-packages/nltk/parse/featurechart.py", line 24, in <module> import nltk.data File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 41, in <module> import zipfile File "/usr/lib/python2.7/zipfile.py", line 460, in <module> class ZipExtFile(io.BufferedIOBase): AttributeError: 'module' object has no attribute 'BufferedIOBase' 

I am trying to import the nltk module

+4
source share
3 answers

You called the script in the same io.py directory, and this interferes with the io module in stdlib. Rename it.

+9
source

You should have a script in your folder named nltk.py, io.py, zipfile.py or some of them. When you run the file in the same directory, it is imported instead of the corresponding python or nltk module.

+2
source

Where is nltk? Is this pure Python code? You may want to put this in the modules folder on the whole site or in your cwd.

0
source

Source: https://habr.com/ru/post/1399849/


All Articles