Python 导入错误:没有名为“资源”的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37710848/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 19:50:07  来源:igfitidea点击:

ImportError: No module named 'resource'

pythonpython-3.xresources

提问by codecodercoding

I am using python 3.5 and I am doing Algorithms specialization courses on Coursera. Professor teaching this course posted a program which can help us to know the time and memory associated with running a program. It has import resourcecommand at the top. I tried to run this program along with the programs I have written in python and every time I received ImportError: No module named 'resource'

我正在使用 python 3.5,我正在 Coursera 上做算法专业课程。教授这门课程的教授发布了一个程序,可以帮助我们了解运行程序所需的时间和内存。它import resource在顶部有命令。我尝试将这个程序与我用 python 编写的程序一起运行,每次我收到ImportError: No module named 'resource'

I used the same code in ubuntu and have no errors at all.

我在 ubuntu 中使用了相同的代码,完全没有错误。

I followed suggestions in stackoverflow answers and I have tried adding PYTHONPATH PYTHONHOME and edited the PATH environment variable.

我遵循了 stackoverflow 答案中的建议,并尝试添加 PYTHONPATH PYTHONHOME 并编辑了 PATH 环境变量。

I have no idea of what else I can do here.

我不知道我还能在这里做什么。

Is there any file that I can download and install it in the Lib or site-packages folder of my python installation ?

是否有任何文件可以下载并安装在我的 python 安装的 Lib 或 site-packages 文件夹中?

回答by Doshmajhan

resourceis a Unix specific package as seen in https://docs.python.org/2/library/resource.htmlwhich is why it worked for you in Ubuntu, but raised an error when trying to use it in Windows.

resource是一个 Unix 特定的包,如https://docs.python.org/2/library/resource.html 中所示,这就是它在 Ubuntu 中为您工作的原因,但在尝试在 Windows 中使用它时引发错误。

回答by gordon1hd1

I ran into similar error in window 10. Here is what solved it for me.

我在窗口 10 中遇到了类似的错误。这是为我解决的问题。

  1. Downgrade to the Apache Spark 2.3.2 prebuild version
  2. Install (or downgrade) jdk to version 1.8.0
    • My installed jdk was 1.9.0, which doesn't seem to be compatiable with spark 2.3.2 or 2.4.0
  3. make sure that when you run java -version in cmd (command prompt), it show java version 8. If you are seeing version 9, you will need to change your system ENV PATH to ensure it points to java version 8.
  4. Check this linkto get help on changing the PATH if you have multiple java version installed.
  1. 降级到 Apache Spark 2.3.2 预构建版本
  2. 安装(或降级)jdk 到 1.8.0 版
    • 我安装的 jdk 是 1.9.0,这似乎与 spark 2.3.2 或 2.4.0 不兼容
  3. 确保当您在 cmd(命令提示符)中运行 java -version 时,它显示 java 版本 8。如果您看到版本 9,则需要更改系统 ENV PATH 以确保它指向 java 版本 8。
  4. 如果您安装了多个 Java 版本,请检查此链接以获取有关更改 PATH 的帮助。

Hope this helps someone, I was stuck on this issue for almost a week before finally finding a solution.

希望这对某人有所帮助,在最终找到解决方案之前,我被困在这个问题上将近一个星期。