Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImportError not clear when causing by import lxml failed #69

Closed
HANK538 opened this issue May 15, 2019 · 5 comments · Fixed by #70
Closed

ImportError not clear when causing by import lxml failed #69

HANK538 opened this issue May 15, 2019 · 5 comments · Fixed by #70

Comments

@HANK538
Copy link

HANK538 commented May 15, 2019

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?

@mlouielu
Copy link
Owner

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.

@HANK538
Copy link
Author

HANK538 commented May 15, 2019

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?

@mlouielu
Copy link
Owner

mlouielu commented May 15, 2019

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

@HANK538
Copy link
Author

HANK538 commented May 15, 2019

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.

@HANK538 HANK538 closed this as completed May 15, 2019
@mlouielu
Copy link
Owner

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.

@mlouielu mlouielu reopened this May 15, 2019
@mlouielu mlouielu changed the title import twstock fail ImportError not clear when causing by import lxml failed May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants