【问题标题】:ModuleNotFoundError: No module named 'camelot' | Works in Jupyter Notebooks but not VSCodeModuleNotFoundError:没有名为“camelot”的模块 |适用于 Jupyter Notebooks 但不适用于 VSCode
【发布时间】:2022-01-13 06:12:11
【问题描述】:

目标:通过PDF 获得此tutorial 的工作版本。 Visual Studio 代码。

我正在尝试通过安装camelotVSCode,使用 Poetry,但存在依赖问题。

这适用于 Jupyter Notebooks(帖子底部),但我正在尝试附加到现有的 .py 项目。

代码:

import glob
import camelot
import pandas as pd
import multiprocessing.dummy as mp

import ctypes
from ctypes.util import find_library
find_library("".join(("gsdll", str(ctypes.sizeof(ctypes.c_voidp) * 8), ".dll")))


PDF_LIST = glob.glob('../data/gri/reports/*.pdf')

def scrape_tables(pdf_filename):
    tables = camelot.read_pdf(pdf_filename)
    print("Total tables extracted:", tables.n)
    return tables

p = mp.Pool(len(PDF_LIST))
pdf_esg_scraped = p.map(scrape_tables, PDF_LIST)

pip install camelot-py:

Traceback (most recent call last):
  File "scrape_tables.py", line 25, in <module>
    import camelot
ModuleNotFoundError: No module named 'camelot'

pip install camelot:

danielbellhv@PF2DCSXD:/mnt/c/Users/dabell/Documents/GitHub/workers-python/workers/data_simulator/src$ pip install camelot
^[[A^[[A
Requirement already satisfied: camelot in /home/me/.local/lib/python3.8/site-packages (12.6.29)
Requirement already satisfied: Elixir>=0.7.1 in /home/me/.local/lib/python3.8/site-packages (from camelot) (0.7.1)
Requirement already satisfied: SQLAlchemy<0.8.0,>=0.7.7 in /home/me/.local/lib/python3.8/site-packages (from camelot) (0.7.10)
Requirement already satisfied: xlrd==0.7.1 in /home/me/.local/lib/python3.8/site-packages (from camelot) (0.7.1)
Requirement already satisfied: Jinja2>=2.5.5 in /usr/lib/python3/dist-packages (from camelot) (2.10.1)
Requirement already satisfied: xlwt==0.7.2 in /home/me/.local/lib/python3.8/site-packages (from camelot) (0.7.2)
Requirement already satisfied: sqlalchemy-migrate>=0.7.1 in /home/me/.local/lib/python3.8/site-packages (from camelot) (0.11.0)
Requirement already satisfied: chardet>=1.0.1 in /usr/lib/python3/dist-packages (from camelot) (3.0.4)
Requirement already satisfied: decorator in /home/me/.local/lib/python3.8/site-packages (from sqlalchemy-migrate>=0.7.1->camelot) (5.1.0)
Requirement already satisfied: pbr>=1.8 in /home/me/.local/lib/python3.8/site-packages (from sqlalchemy-migrate>=0.7.1->camelot) (5.8.0)
Requirement already satisfied: Tempita>=0.4 in /home/me/.local/lib/python3.8/site-packages (from sqlalchemy-migrate>=0.7.1->camelot) (0.5.2)
Requirement already satisfied: six>=1.7.0 in /usr/lib/python3/dist-packages (from sqlalchemy-migrate>=0.7.1->camelot) (1.14.0)
Requirement already satisfied: sqlparse in /home/me/.local/lib/python3.8/site-packages (from sqlalchemy-migrate>=0.7.1->camelot) (0.4.2)

尝试的解决方案:

我在 Jupyter Notebook 中得到了 Ghostscript 文件路径输出。

import ctypes
from ctypes.util import find_library
find_library("".join(("gsdll", str(ctypes.sizeof(ctypes.c_voidp) * 8), ".dll")))
>>> 'C:\\Users\\me\\Anaconda3\\Library\\bin\\gsdll64.dll'

使用这个输出,我需要"append new location to the PATH variable"

但是,这仍然不起作用。我尝试过的变体:

PATH=$PATH:C:\Users\me\Anaconda3\Library\bin\gsdll64.dll
PATH=$PATH:C:\\Users\\me\\Anaconda3\\Library\\bin\\gsdll64.dll
PATH=$PATH:'c/Users/me/Anaconda3/Library/bin/gsdll64.dll'
PATH=$PATH:'/mnt/c/Users/me/Anaconda3/Library/bin/gsdll64.dll'

export PATH="$HOME/.poetry/bin:$PATH";C:/Users/me/Anaconda3/Library/bin/gsdll64.dll
bash: C:/Users/me/Anaconda3/Library/bin/gsdll64.dll: No such file or directory

此外,为了让 Poetry 工作,我需要让PATH 指向它的位置:

export PATH="$HOME/.poetry/bin:$PATH"

我可以有多个PATH 变量吗?

【问题讨论】:

  • 让 VS Code 使用与您的系统相同的 Python 版本和库路径是常见的常见问题解答。提问前请先搜索。
  • 我不完全理解你的问题。在任何情况下,pip install camelot 您都不是在安装 Camelot 表提取工具,而是另一个软件包。正确的安装命令是pip install camelot-py(见camelot-py.readthedocs.io/en/master/user/install.html)。
  • 会试试pip install camelot-py
  • Traceback (most recent call last): File "scrape_tables.py", line 25, in &lt;module&gt; import camelot ModuleNotFoundError: No module named 'camelot'

标签: python python-3.x path modulenotfounderror python-camelot


【解决方案1】:

有时在 VSCode 中安装了模块但它无法识别新模块,在 VSCode 的左侧按钮中单击 python 版本并将其更改为另一个版本,然后在返回到您的第一个 python 版本后安装模块在上面。

【讨论】:

  • VSCode 对我来说是 WSL: Ubunutu,但我使用的是 Python
  • 适用于 Linux 的 Windows 子系统仍然是 Ubuntu。
猜你喜欢
  • 2020-10-22
  • 1970-01-01
  • 2023-04-01
  • 2021-02-07
  • 2018-02-01
  • 2020-03-16
  • 2018-10-09
  • 2017-07-08
  • 2020-09-02
相关资源
最近更新 更多