简体   繁体   English

导入python包-初学者问题

[英]importing python package -beginner question

I downloaded a package online from https://pypi.org/project/Random-Word/#description its a random English word file.我从https://pypi.org/project/Random-Word/#description在线下载了一个包,它是一个随机的英文单词文件。 I downloaded it using pip install.我使用 pip install 下载了它。 it is a .whl file when downloaded.下载时它是一个 .whl 文件。 However in the project description he lists his basic usage as a .py file... I'm not sure how to import it into my program because its installed as a .whl file and the module isn't found when I try to import it.但是在项目描述中,他将他的基本用法列为 .py 文件......我不知道如何将它导入我的程序,因为它安装为 .whl 文件,并且在我尝试导入时找不到该模块它。

Is there a way to convert .whl files to .py files in order for my program to see it as a module, be able to import it and use it in a program?有没有办法将 .whl 文件转换为 .py 文件,以便我的程序将其视为模块,能够导入它并在程序中使用它? or is there a better way of doing this?或者有没有更好的方法来做到这一点?

If you installed it like this:如果你是这样安装的:

pip(3) install random-word

Create a .py file and place the following in it:创建一个 .py 文件并将以下内容放入其中:

from random_word import RandomWords
r = RandomWords()
print(r.get_random_word())

Then run the PY file:然后运行 ​​PY 文件:

python(3) <file>.py

Essentially, you need to import RandomWords from the random_word directory, instead if just import RandomWords从本质上讲,你需要import RandomWordsrandom_word目录,而不是如果恰好import RandomWords

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM