Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
985 views
in Technique[技术] by (71.8m points)

python - ImportError: No module named 'version'

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:Python34libsite-packagesopencc\__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:Python34libsite-packagesopencc

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,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...