Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImportError: No module named 'version'

Tags:

python

I pip the "opencc"

when i shell the code below

import opencc

it shows

Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import opencc
File "C:\Python34\lib\site-packages\opencc\__init__.py", line 6, in <module>
from version import __version__ 
ImportError: No module named 'version'

but "____init__.py"and"version.py" are in the same directory C:\Python34\lib\site-packages\opencc

opencc
    |----__init__.py
    |----version.py

file:version.py

__version__ = '0.1'

when i change

from version import __version__

into

__version__ = '0.1'

opencc,it works

I know it doesn't make a big difference,but i just want to know why the init.py can't import the module version.py in the same directory,

like image 326
f.BigBro Avatar asked Sep 06 '15 12:09

f.BigBro


1 Answers

The opencc module is not compatible with Python 3. It can currently only be used on Python 2.

Specifically, the version module is part of the opencc package, but in Python 3 you'd need to use absolute imports, from opencc.version import __version__ or from .version import __version__. There will be other issues with the code too.

like image 155
Martijn Pieters Avatar answered Oct 01 '22 19:10

Martijn Pieters