0

I downloaded a package online from https://pypi.org/project/Random-Word/#description its a random English word file. I downloaded it using pip install. it is a .whl file when downloaded. 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.

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? or is there a better way of doing this?

Carina
  • 3
  • 7
  • 1
    https://stackoverflow.com/questions/27885397/how-do-i-install-a-python-package-with-a-whl-file – Shijith Oct 23 '20 at 19:49

1 Answers1

1

If you installed it like this:

pip(3) install random-word

Create a .py file and place the following in it:

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

Then run the PY file:

python(3) <file>.py

Essentially, you need to import RandomWords from the random_word directory, instead if just import RandomWords

  • 1
    I installed it on cd pip install --user Random_Word-1.0.4-py3-none-any.whl would this way use your method as well? – Carina Oct 23 '20 at 20:19
  • 1
    i guess im confused on how python or the cd is able to know that Random_Word-1.0.4-py3-none-any.whl is the same as random-word? they're not spelled the same way am i missing something here? – Carina Oct 23 '20 at 20:24
  • To use the package, just pip(3) install and you'll be able to use it. Some packages use classes, so you will need to from import –  Oct 23 '20 at 20:25
  • are you putting pip(3) install Random_Word-1.0.4-py3-none-any.whl in the cmd prompt? i'm getting an error saying ERROR: unknown command "(3)". – Carina Oct 23 '20 at 21:05
  • there's pip and then there's pip3. you either pip install or pip3 install , either will do. For this one, pip(3) install random_word –  Oct 23 '20 at 21:42
  • okay i used pip install random_word and it looks like it installed it. I created the .py file and this error popped up ImportError: cannot import name 'RandomWords' from 'random_word' – Carina Oct 23 '20 at 22:42
  • If you executed this command: "pip install random-word" or this command: "pip3 install random-word", then you should be able to use this: "from random_word import RandomWords". Can you try this, to see if it is installed: "pip(3) show random-word" –  Oct 23 '20 at 23:27
  • the cmd prompt shows all the information from where i got it from ect and a short description of where it is. So it is installed. However I'm trying to import it into a pycharms program. i type it just as: from random_word import RandomWords and its greyed out. When i hover over the word random_word and RandomWords it says unresolved reference. when i execute it in pycharms it says Error: cannot import name 'RandomWords' from 'random_word'. is there a certain place where the .py file should be located maybe its a path issue? side not i really appreciate you taking the time to help me thus far. – Carina Oct 25 '20 at 00:44
  • I've never used pycharm except for a school project, can you try doing so with a regular py file outside of pycharm? maybe then we can tell if its pycharm causing the issue. –  Oct 25 '20 at 17:38
  • how would i do that? can i create a .py file from the cmd prompt? – Carina Oct 26 '20 at 23:34
  • Do you have any experience with jupyter notebooks? Its the only other editor i can think of and im not sure how to create a .py file there only .text and .ipynb. – Carina Oct 28 '20 at 21:46
  • Nope, never used it. I have the text extension on chrome os: https://chrome.google.com/webstore/detail/text/mmfbcljfglbokpmkimbfghdkjmjhdgbg?hl=en, and nano on linux (sudo apt-get install nano) –  Oct 29 '20 at 00:48
  • Okay, i have downloaded the chrome extension to try it your way. Would you just type what you said before and save it as a .py file? or is there a specific way for the extension? – Carina Oct 29 '20 at 01:05
  • Type the example from my original comment, and save it as file.py. then run it with python (python3 file.py) –  Oct 29 '20 at 01:23
  • I've created the file however i'm having trouble figuring out how to run it on this extension. Is there a keyboard short cut for it? – Carina Oct 30 '20 at 00:52
  • Assuming it is in your python directory, you'd run it in your terminal. –  Oct 30 '20 at 02:14