ImportError: No module named 'version' - 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,

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.

add package , or coppy it to cp -R Version /usr/local/lib/python3.9 it work for me

Related

ModuleNotFoundError: No module named 'util'

I had an Import err that says "No module named util", but i cant find any package named util.
what path should I append in?
Code from LSTNet tensorflow by fabdline.
https://github.com/fbadine/LSTNet
# Path appended in order to import from util
import sys
#sys.path.append("..")
sys.path.append('../') #?what path should I Append?
import os
from util.model_util import LoadModel, SaveModel, SaveResults, SaveHistory
from util.Msglog import LogInit
Traceback (most recent call last): File "main.py", line 19, in
from util.model_util import LoadModel, SaveModel, SaveResults, SaveHistory ModuleNotFoundError: No module named 'util'
Follow the install instructions from the link you posted.
Under Installation it's stated:
Clone this prerequisite repository:
git clone https://github.com/fbadine/util.git
All the files you need can be found at https://github.com/fbadine/util

How I can use 'regex' package in python without installation?

I want to use regex package without installation (neither using pip nor python setup.py install)
For that, I have downloaded the package and kept in the same directory of the file where I am importing regex. The code is given below
import sys
import os
currentdirectory = os.getcwd()
sys.path.append(currentdirectory+"/packages/regex/Python2/")
from regex import *
I am getting following error as _regex extension module is not created.
Traceback (most recent call last):
File "test.py", line 30, in <module>
from regex import *
File "/Users/nilakshi/test_branch/packages/regex/Python2/regex.py", line 387, in <module>
import _regex_core
File "/Users/nilakshi/test_branch/packages/regex/Python2/_regex_core.py", line 21, in <module>
import _regex
ImportError: No module named _regex
How do I create _regex extension module that can be locally used?
Also, can I create _regex extension module file such that I can use the same file in different machines without creating again?

After installed asprise_ocr_sdk_python_api on mac, got "No module named 'ocr'"

I ran both
sudo pip install asprise_ocr_sdk_python_api
pip install asprise_ocr_sdk_python_api
Got message
"Requirement already satisfied: asprise_ocr_sdk_python_api in /Users/myid/miniconda3/envs/competition/lib/python3.5/site-packages"
But when I ran asprise_ocr to test:
Got the following error:
Traceback (most recent call last):
File "/Users/myuser/miniconda3/envs/competition/bin/asprise_ocr", line 7, in <module>
from asprise_ocr_api.ocr_app import run_ocr_app
File "/Users/myuser/miniconda3/envs/competition/lib/python3.5/site-packages/asprise_ocr_api/__init__.py", line 1, in <module>
from ocr import *
ImportError: No module named 'ocr'
The asprise_ocr_api module doesn't do submodule imports correctly in Python 3.
For example init.py contains from ocr import *. For a sub-module in Python 3 that should be from .ocr import *. Idem for from ocr_app import OcrApp, run_ocr_app. That should be from .ocr_app import OcrApp, run_ocr_app.
After making these changes in all files it imports correctly.
i've tried:
import ocr
same error:
ModuleNotFoundError: No module named 'ocr'
i am using python 3

ImportError: cannot import name MAXREPEAT [duplicate]

I'm running into an issue with cx_Freeze when running a frozen application (works fine unfrozen).
When running the program it results in the following traceback:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/Console.py", line 27, in <module>
exec code in m.__dict__
File "PythonApp/mainframe.py", line 3, in <module>
File "/usr/local/lib/python2.7/site-packages/dbus/__init__.py", line 103, in <module>
from dbus._dbus import Bus, SystemBus, SessionBus, StarterBus
File "/usr/local/lib/python2.7/site-packages/dbus/_dbus.py", line 39, in <module>
from dbus.bus import BusConnection
File "/usr/local/lib/python2.7/site-packages/dbus/bus.py", line 39, in <module>
from dbus.connection import Connection
File "/usr/local/lib/python2.7/site-packages/dbus/connection.py", line 27, in <module>
import threading
File "/usr/local/lib/python2.7/threading.py", line 44, in <module>
module='threading', message='sys.exc_clear')
File "/usr/local/lib/python2.7/warnings.py", line 57, in filterwarnings
import re
File "/usr/local/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/usr/local/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/usr/local/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/usr/local/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
I'm on linux using a version of python 2.7.4 that I built from source, and importing _sre from a prompt works and I can access the MAXREPEAT constant.
This is usually down to cx_Freeze not pulling everything into library.zip and can be fixed by explicitly naming the module in cx_Freezes setup include list and is the solution to this similar question, but that hasn't helped here.
This _sre module seems weird.. there's no _sre file in the library.zip generated but from that error it seems like it can find it, however it can't import that symbol? Surely if the module wasn't there it would be a "No module named _sre" error. Or possibly a circular import but _sre stub doesn't have any imports.
What's odd is I can't seem to find the file either - is this module dynamically created when importing somehow?
find /usr/local/lib/python2.7 -name "_sre*"
doesn't return anything, and the imported _sre module doesn't have a __file__ attribute either, so I've no idea how to make sure it's included as it shows up as a built-in.
>>> import _sre
>>> _sre.__file__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__file__'
>>> repr(_sre)
"<module '_sre' (built-in)>"
This is similar to this question also which was asked recently, but in this case he was getting the error in the regular interpreter, however for me it's just in cx_Freeze.
edit
Running python -v does seem like it's a built-in, so I'm not sure why cx_Freeze can miss it, or how I'd fix it.
...
# /usr/local/lib/python2.7/re.pyc matches /usr/local/lib/python2.7/re.py
import re # precompiled from /usr/local/lib/python2.7/re.pyc
# /usr/local/lib/python2.7/sre_compile.pyc matches /usr/local/lib/python2.7/sre_compile.py
import sre_compile # precompiled from /usr/local/lib/python2.7/sre_compile.pyc
import _sre # builtin
# /usr/local/lib/python2.7/sre_parse.pyc matches /usr/local/lib/python2.7/sre_parse.py
import sre_parse # precompiled from /usr/local/lib/python2.7/sre_parse.pyc
...
I encountered this problem when I just upgraded from ubuntu 12.10 to 13.04, and I fixed this by copying the /usr/bin/python to /path/to/my/env/bin/, and it worked just fine
cp /user/bin/python /path/to/my/env/bin/
or, there's a more elegant way to fix this(reference):
mkvirtualenv <existing virtualenv name>
_sre is a built in module, so there's no file to include for it, but it doesn't have a MAXREPEAT attribute in Python 2.7.3:
>>> import _sre
>>> _sre
<module '_sre' (built-in)>
>>> _sre.MAXREPEAT
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'MAXREPEAT'
My best guess is that your frozen copy somehow has the standard library .py modules from Python 2.7.4, but the compiled Python interpreter from 2.7.3 or an earlier version. I see you're working from /usr/local - maybe it's picking up an older version from /usr.
If all else fails, I got things running using this: http://www.kiwisoft.co.uk/blog/2014/08/17/fixed-importerror-cannot-import-name-maxrepeat
I had the same problem recently. Setting LD_LIBRARY_PATH=
solved the problem.
I was using cx_freeze 4.3.2 on my win 8 machine and it was always showing ImportError: cannot import name MAXREPEAT with cx Freeze if I ever tried to freeze a non built-in module, and once I downloaded version 4.3.1, it works, I'm able to freeze my all python 3.3 programs without any problem now.
I was having similar issues on windows 8 - was just a PYTHONPATH issue. check that PYTHONPATH exists by typing the following into a python session:
import os
os.environ['PYTHONPATH'].split(os.pathsep)
if you get an error set your PYTHONPATH using this approach..
How to add to the pythonpath in windows 7?

ImportError: cannot import name MAXREPEAT with cx_Freeze

I'm running into an issue with cx_Freeze when running a frozen application (works fine unfrozen).
When running the program it results in the following traceback:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/site-packages/cx_Freeze/initscripts/Console.py", line 27, in <module>
exec code in m.__dict__
File "PythonApp/mainframe.py", line 3, in <module>
File "/usr/local/lib/python2.7/site-packages/dbus/__init__.py", line 103, in <module>
from dbus._dbus import Bus, SystemBus, SessionBus, StarterBus
File "/usr/local/lib/python2.7/site-packages/dbus/_dbus.py", line 39, in <module>
from dbus.bus import BusConnection
File "/usr/local/lib/python2.7/site-packages/dbus/bus.py", line 39, in <module>
from dbus.connection import Connection
File "/usr/local/lib/python2.7/site-packages/dbus/connection.py", line 27, in <module>
import threading
File "/usr/local/lib/python2.7/threading.py", line 44, in <module>
module='threading', message='sys.exc_clear')
File "/usr/local/lib/python2.7/warnings.py", line 57, in filterwarnings
import re
File "/usr/local/lib/python2.7/re.py", line 105, in <module>
import sre_compile
File "/usr/local/lib/python2.7/sre_compile.py", line 14, in <module>
import sre_parse
File "/usr/local/lib/python2.7/sre_parse.py", line 17, in <module>
from sre_constants import *
File "/usr/local/lib/python2.7/sre_constants.py", line 18, in <module>
from _sre import MAXREPEAT
ImportError: cannot import name MAXREPEAT
I'm on linux using a version of python 2.7.4 that I built from source, and importing _sre from a prompt works and I can access the MAXREPEAT constant.
This is usually down to cx_Freeze not pulling everything into library.zip and can be fixed by explicitly naming the module in cx_Freezes setup include list and is the solution to this similar question, but that hasn't helped here.
This _sre module seems weird.. there's no _sre file in the library.zip generated but from that error it seems like it can find it, however it can't import that symbol? Surely if the module wasn't there it would be a "No module named _sre" error. Or possibly a circular import but _sre stub doesn't have any imports.
What's odd is I can't seem to find the file either - is this module dynamically created when importing somehow?
find /usr/local/lib/python2.7 -name "_sre*"
doesn't return anything, and the imported _sre module doesn't have a __file__ attribute either, so I've no idea how to make sure it's included as it shows up as a built-in.
>>> import _sre
>>> _sre.__file__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__file__'
>>> repr(_sre)
"<module '_sre' (built-in)>"
This is similar to this question also which was asked recently, but in this case he was getting the error in the regular interpreter, however for me it's just in cx_Freeze.
edit
Running python -v does seem like it's a built-in, so I'm not sure why cx_Freeze can miss it, or how I'd fix it.
...
# /usr/local/lib/python2.7/re.pyc matches /usr/local/lib/python2.7/re.py
import re # precompiled from /usr/local/lib/python2.7/re.pyc
# /usr/local/lib/python2.7/sre_compile.pyc matches /usr/local/lib/python2.7/sre_compile.py
import sre_compile # precompiled from /usr/local/lib/python2.7/sre_compile.pyc
import _sre # builtin
# /usr/local/lib/python2.7/sre_parse.pyc matches /usr/local/lib/python2.7/sre_parse.py
import sre_parse # precompiled from /usr/local/lib/python2.7/sre_parse.pyc
...
I encountered this problem when I just upgraded from ubuntu 12.10 to 13.04, and I fixed this by copying the /usr/bin/python to /path/to/my/env/bin/, and it worked just fine
cp /user/bin/python /path/to/my/env/bin/
or, there's a more elegant way to fix this(reference):
mkvirtualenv <existing virtualenv name>
_sre is a built in module, so there's no file to include for it, but it doesn't have a MAXREPEAT attribute in Python 2.7.3:
>>> import _sre
>>> _sre
<module '_sre' (built-in)>
>>> _sre.MAXREPEAT
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'MAXREPEAT'
My best guess is that your frozen copy somehow has the standard library .py modules from Python 2.7.4, but the compiled Python interpreter from 2.7.3 or an earlier version. I see you're working from /usr/local - maybe it's picking up an older version from /usr.
If all else fails, I got things running using this: http://www.kiwisoft.co.uk/blog/2014/08/17/fixed-importerror-cannot-import-name-maxrepeat
I had the same problem recently. Setting LD_LIBRARY_PATH=
solved the problem.
I was using cx_freeze 4.3.2 on my win 8 machine and it was always showing ImportError: cannot import name MAXREPEAT with cx Freeze if I ever tried to freeze a non built-in module, and once I downloaded version 4.3.1, it works, I'm able to freeze my all python 3.3 programs without any problem now.
I was having similar issues on windows 8 - was just a PYTHONPATH issue. check that PYTHONPATH exists by typing the following into a python session:
import os
os.environ['PYTHONPATH'].split(os.pathsep)
if you get an error set your PYTHONPATH using this approach..
How to add to the pythonpath in windows 7?

Categories

Resources