Python在Linux中出现错误信息:”ImportError: No module named X”,但库存在。

huangapple go评论77阅读模式
英文:

Python in Linux: "ImportError: No module named X", but library exists

问题

我最近在我的服务器上安装了Selenium并更新了一个Python脚本。每当我尝试执行该脚本时,我会收到“ImportError Module: No module named schedule”的错误消息,尽管已经安装了该模块:

由于正常的site-packages不可写,因此默认使用用户安装
Requirement already satisfied: schedule in ./JET/.local/lib/python3.8/site-packages (1.1.0)

这种情况发生在每个库上,而且每个库都已安装。

我不想将这个包放在与脚本相同的文件夹中,因为这会导致更多错误。

我通过另一个Shell脚本执行该脚本,但以前从未遇到过这个错误。

我猜测与PATH有关,但我不知道该怎么办。

英文:

I've recently updated a python script of mine on my server after installing Selenium. Whenever I try to execute the script: I get "ImportError Module: No module named schedule", even tho it is installed:

Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: schedule in ./JET/.local/lib/python3.8/site-packages (1.1.0)

It happens with every library, and every library is installed.

I don't want to place the package in the same folder as the script, it raises even more errors.

I execute the script via another shell script, but it never gave me this error before.

My guessings are it has to do with PATH, but I don't know what to do.

答案1

得分: 1

抱歉,我只返回翻译好的部分,不包括代码部分。以下是翻译好的内容:

"Hi, I wonder if that could be related to [this question](https://stackoverflow.com/questions/55587418/importerror-no-module-named-schedule-when-i using-system-to-run-a-service) or this another one.

I wonder if adding path before the import might help

import sys 
sys.path.append("./JET/.local/lib/python3.8/site-packages")
import schedule
```"

<details>
<summary>英文:</summary>

(Sorry for not writing this as a comment, but I cannot comment yet.)

Hi, I wonder if that could be related to [this question](https://stackoverflow.com/questions/55587418/importerror-no-module-named-schedule-when-i-using-system-to-run-a-service) or [this another one](https://stackoverflow.com/questions/73260371/modulenotfounderror-no-module-named-schedule). 

I wonder if adding path before the import might help
``` python
import sys 
sys.path.append(&quot;./JET/.local/lib/python3.8/site-packages&quot;)
import schedule

huangapple
  • 本文由 发表于 2023年5月29日 00:14:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/76352421.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定