简体   繁体   中英

ModuleNotFoundError: No module named 'version'

I am using Python 3 along with SOAPpy Library in conjunction with my code. I keep getting a " ModuleNotFoundError: No module named 'version' " error when trying to run my code. The error is coming from this specific line within the Library:

from version import __version__

How do I fix the error?

People usually set the variable __version__ in a module to make it available to the world to inspect, it even has a PEP !

I'm not sure about which line you are referring to but there are many with the same incriminating import in the SOAPpy package.

You can see here that the package indeed has a version module defining a __version__ variable. I don't know how are you including this package in your project but I'll explain something about imports, you can read more here .

The incriminating line can have two alternatives

from .version import __version__ # relative import

from SOAPpy.version import __version__ # absolute import

You could read them as "paths", the first is the version.py file in the current directory, the second is the version.py file in the SOAPpy directory.

They are both fine but sometimes repeating SOAPpy everywhere is too much work.

Let's fix the line to have a relative import

diff --git a/SOAPpy/__init__.py b/SOAPpy/__init__.py
index 0e039f8..832a560 100644
--- a/SOAPpy/__init__.py
+++ b/SOAPpy/__init__.py
@@ -1,15 +1,15 @@

 ident = '$Id: __init__.py,v 1.9 2004/01/31 04:20:06 warnes Exp $'
-from version import __version__
+from .version import __version__

-from Client      import *
-from Config      import *
-from Errors      import *
-from NS          import *
-from Parser      import *
-from SOAPBuilder import *
-from Server      import *
-from Types       import *
-from Utilities     import *
+from .Client      import *
+from .Config      import *
+from .Errors      import *
+from .NS          import *
+from .Parser      import *
+from .SOAPBuilder import *
+from .Server      import *
+from .Types       import *
+from .Utilities     import *
 import wstools
 import WSDL

And indeed now if I run python setup.py install I get a different error

Traceback (most recent call last):
  File "setup.py", line 8, in <module>
    from SOAPpy.version import __version__
  File "/home/edoput/repo/SOAPpy/SOAPpy/__init__.py", line 5, in <module>
    from .Client      import *
  File "/home/edoput/repo/SOAPpy/SOAPpy/Client.py", line 95
    raise IOError, "unsupported SOAP protocol"
                 ^
SyntaxError: invalid syntax

So indeed it might be a problem that this library has not been upgraded to use python3!

Let's use python2 instead, even if we should not .

virtualenv env --python=python2
source env/bin/activate
python setup.py install

And now everything installs correctly, this library has definitely not been updated recently, you can still use it but you have to stick to use python 2.7. Have fun!

SOAPpy ( pypy ) seems to be an outdated library meant for python2, which is why some of the code in the library produces these errors. You might have better luck using Zeep - a modern SOAP python3 compatible client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM