I couldn't import the python module with VSCODE, but I could do it on juoyterlab, so I'm talking about finding the cause.

The other day, an event occurred that suddenly the python module pyquery could not be imported on VSCODE. The details of the error are as follows.

qiita.rb


Traceback (most recent call last):
  File "c:\Users\name\Documents\excel_python\python_prg\today_stockinfo_toDB.py", line 1, in <module>
    from pyquery import PyQuery
  File "D:\Anaconda3\lib\site-packages\pyquery\__init__.py", line 7, in <module>
    from .pyquery import PyQuery  # NOQA
  File "D:\Anaconda3\lib\site-packages\pyquery\pyquery.py", line 11, in <module>
    from lxml import etree
ImportError: DLL load failed:The specified module cannot be found.
PS C:\Users\name\Documents\excel_python\python_prg> conda activate base

However, since the imporet of pyquery was created on jupyterlab without any problem, I will investigate the cause.

First, check if the module exists on vscode.

qiita.rb


$ py -m pip list
・
・
・
・
pyquery                            1.4.1

was.

Next, check the path where this pyquery is stored.

qiita.rb


$ py -m pip show pyquery
・
・
・
Location: d:\anaconda3\lib\site-packages

I was able to confirm that it exists in this path.

Next, compare the path that goes around on Jupyter Lab and the path that goes around on VSCODE.

First of all, jupyterlab's

qiita.rb


import sys
sys.path


['C:\\Users\\name\\Documents\\excel_python\\python_prg',
 'D:\\Anaconda3\\python37.zip',
 'D:\\Anaconda3\\DLLs',
 'D:\\Anaconda3\\lib',
 'D:\\Anaconda3',
 '',
 'D:\\Anaconda3\\lib\\site-packages',
 'D:\\Anaconda3\\lib\\site-packages\\win32',
 'D:\\Anaconda3\\lib\\site-packages\\win32\\lib',
 'D:\\Anaconda3\\lib\\site-packages\\Pythonwin',
 'D:\\Anaconda3\\lib\\site-packages\\IPython\\extensions',
 'C:\\Users\\name\\.ipython']

d: \ anaconda3 \ lib \ site-packages is included.

Then the one on VSCODE

qiita.rb


import sys
sys.path

'c:\\Users\\name\\Documents\\excel_python\\python_prg', 
 'D:\\Anaconda3\\python37.zip', 
 'D:\\Anaconda3\\DLLs', 
 'D:\\Anaconda3\\lib', 
 'D:\\Anaconda3', 
 'D:\\Anaconda3\\lib\\site-packages', 
 'D:\\Anaconda3\\lib\\site-packages\\win32', 
 'D:\\Anaconda3\\lib\\site-packages\\win32\\lib', 
 'D:\\Anaconda3\\lib\\site-packages\\Pythonwin']

Ah, both include d: \ anaconda3 \ lib \ site-packages. Funny, pyquery exists, both pass through the path, but on jupyterlab Can it be started and cannot be started on vscode?

I'm sorry to say that the path that VSCODE doesn't pass is'D: \ Anaconda3 \ lib \ site-packages \ IPython \ extensions','C: \ Users \ name \ .ipython' Even with vscode I tried adding it, but no improvement was seen in the symptoms. When using pyquery for a while, it seems that I will be forced to use it on jupyterlab.

Recommended Posts

I couldn't import the python module with VSCODE, but I could do it on juoyterlab, so I'm talking about finding the cause.
I couldn't import the python module with VSCODE, but I could do it on jupyterlab, so I searched for the cause (2)
I want to tweet on Twitter with Python, but I'm addicted to it
Life game with Python [I made it] (on the terminal & Tkinter)
I want to do it with Python lambda Django, but I will stop
Python coding: I'm not sure about Nantoka so I looked it up
I'm an amateur on the 14th day of python, but I want to try machine learning with scikit-learn
CUM_plot, which I often see at the manufacturing site, did not fall on the net, so I made it with python
I tried to scrape YouTube, but I can use the API, so don't do it.
[Memorandum] python + vscode + pipenv It's common, but it was a mess with warning, so a memorandum