ImportError not clear when causing by import lxml failed
HANK538 opened this issue · comments
Hi
I already installed package as below
pip install twstock
pip install analytics
But when I start coding via import twstock
Traceback (most recent call last):
File "d:/Project/A00 Test/stock.py", line 1, in
import twstock
File "C:\Users\10802304\AppData\Roaming\Python\Python37\site-packages\twstock_init_.py", line 3, in
from twstock import stock
File "C:\Users\10802304\AppData\Roaming\Python\Python37\site-packages\twstock\stock.py", line 20, in
import analytics
File "C:\Users\10802304\AppData\Local\Continuum\anaconda3\lib\site-packages\analytics_init_.py", line 23
except Exception, e:
^
SyntaxError: invalid syntax
It seems analytics is incompatible with twstock due to using python2 older version.
Any idea?
Hi @HANK538,
You should not install "analytics", which is not used by twstock, twstock is using its analytics module (twstock/analytics.py
), since you install analytics
package (pip install analytics
), it caused python to find another package.
You can remove the analytics package by $ pip uninstall analytics
, it should solved this issue.
Anyway, it is encouraged to use $ python -m pip ...
to execute pip, since using pip
alone you will not sure which python interpreter is been used for the pip.
Hi mlouielu
Thanks for your reply.
But I encountered below issue after uninstalled analytics.
Traceback (most recent call last):
File "d:/Project/A00 Test/stock.py", line 1, in
import twstock
File "C:\Users\10802304\AppData\Roaming\Python\Python37\site-packages\twstock_init_.py", line 3, in
from twstock import stock
File "C:\Users\10802304\AppData\Roaming\Python\Python37\site-packages\twstock\stock.py", line 21, in
from codes import codes
ModuleNotFoundError: No module named 'codes'
Any solution?
Hi @HANK538
I suggest you can open the file "C:\Users\10802304\AppData\Roaming\Python\Python37\site-packages\twstock\stock.py", and find maybe at line 16 have this:
try:
from . import analytics
from .codes import codes
except ImportError:
import analytics
from codes import codes
Please replace it to this
try:
from . import analytics
from .codes import codes
except ImportError as e:
print('Error: ', e)
import analytics
from codes import codes
Check and paste the otuput of what causing this ImportError, thanks
Thank you for the prompt reply!
ModuleNotFoundError: No module named 'lxml'
It works now after installed twstock and lxml package.
By the way, I just followed below blog so that's why I installed analytics package.
http://yhhuang1966.blogspot.com/2019/04/twstock.html
Thanks a lot.
Thanks for your reply, this should consider as a bug that not intent to be (Is because the dependency lxml didn't install, not because import relative package causing an error).
I'll reopen this issue to fix it.