Closed xuleijian closed 5 years ago
Hi!
1) Which python version do you use? 2) Please, post the stacktrace and the code to reproduce the issue.
Thank you for your reply ! I use version 3.7 !
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/nose/failure.py", line 39, in runTest
raise self.exc_val.with_traceback(self.tb)
File "/usr/local/lib/python3.7/site-packages/nose/loader.py", line 418, in loadTestsFromName
addr.filename, addr.module)
File "/usr/local/lib/python3.7/site-packages/nose/importer.py", line 47, in importFromPath
return self.importFromDir(dir_path, fqname)
File "/usr/local/lib/python3.7/site-packages/nose/importer.py", line 94, in importFromDir
mod = load_module(part_fqname, fh, filename, desc)
File "/usr/local/lib/python3.7/imp.py", line 234, in load_module
return load_source(name, filename, file)
File "/usr/local/lib/python3.7/imp.py", line 171, in load_source
module = _load(spec)
File "
OK, I'll take a look.
@ivankorobkov Any solution find out ?
It seems the problem is with the typing dependency in some environments. I could not reproduce it, will have to look more into int.
I am also having this issue and I think I've figured out what is happening. There are a couple of factors to this issue, first typing was introduced to the stdlib of Python since 3.5. The upstream package of typing is for versions older than 3.5. I believe that Python 3.7 is completely incompatible with this upstream package. Secondly, this is normally not an issue with typical imports as the Python3.7 interpreter usually prioritizes the stdlib over the virtualenv. But, when a system prioritizes the virtualenv over the stdlib, the incompatible typing package is loaded and breaks. To reproduce a system that would do this run the following
Create a python3 virtualenv
virtualenv -p python3.7 venv
Source the venv
Install inject
pip3 install inject
Create a module with the following code. Replace the sys.path with your interpreter paths
import sys
sys.path = [
'<path to newly created venv>/venv/lib/python3.7/site-packages',
'/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7'] # This is my stdlib for my system (on my mac), replace this path with your python3.7 lib path
import inject
6. Run the python module
`python3.7 <your file>`
5. It should then error out with a message like
import inject Traceback (most recent call last): File "
", line 1, in File "/private/tmp/test/venv/lib/python3.7/site-packages/inject.py", line 86, in from typing import Optional, Type, Hashable, Callable, TypeVar, Union File "/private/tmp/test/venv/lib/python3.7/site-packages/typing.py", line 1357, in class Callable(extra=collections_abc.Callable, metaclass=CallableMeta): File "/private/tmp/test/venv/lib/python3.7/site-packages/typing.py", line 1005, in new self._abc_registry = extra._abc_registry AttributeError: type object 'Callable' has no attribute '_abc_registry'
I would recommend making the typing package requirement only necessary for Python3.4 and below
That's a very helpful comment. Thanks a lot for it and for the pull request.
I have released version 3.5.3 with the fix. @xuleijian please, check. https://pypi.org/project/Inject/
When I use the lastest version Inject==3.5.2,I got the error "AttributeError: type object 'Callable' has no attribute '_abc_registry' ". But when I installed the lower version Inject==3.5.1,all the things are OK.Could you give me some help? Thank you !