0

i've installed a python project, and it imports modules(Like almost every project). The problem is when i want to install them(because i haven't got the modules), for example: In the project is imported a module called "a" but when i go and install "a" with pip install a, it says ERROR: Could not find a version that satisfies the requirement a (from versions: none) ERROR: No matching distribution found for a. How could i know the name of the module that is imported in that python project?

Edit: btw i just found out the module that the project uses comes in the zip where the python project is. How could i install it so it works?

  • What is an example of a library that you cannot install? Can you install *any* libraries with pip? – blackbrandt Dec 17 '21 at 18:12
  • @blackbrandt Yes i can install libraries with pip. – MegaNoobyYT Dec 17 '21 at 18:22
  • How did you install this python project? It should have come with a `requirements.txt` file indicating which packages it relies upon, so that they can be installed by pip at the same time you're installing the main project. – MattDMo Dec 17 '21 at 18:25
  • @MattDMo It comes with the modules in the zip i think, because there are py files that have the names imported in the main project – MegaNoobyYT Dec 17 '21 at 18:28
  • Well, if it comes with `.py` files that are named according to the imports, then what's the problem? Those are internal imports; they're not looking for an external module that you need to install... – MattDMo Dec 17 '21 at 18:34
  • @MattDMo the problem is that the program doesn't work – MegaNoobyYT Dec 17 '21 at 18:35
  • @MattDMo It says that the module isnt there: example: ModuleNotFoundError: No module named 'a' – MegaNoobyYT Dec 17 '21 at 18:37
  • Please [edit] your question and add in the crucial details - what specific program you're trying to use, how exactly you installed it, a [mre] of the code that's not working, and the [**full text** of any errors or tracebacks](https://meta.stackoverflow.com/q/359146), *all as formatted text in the question itself.* Do not post images of text. – MattDMo Dec 17 '21 at 18:39

2 Answers2

1

All pip packages are listed here. If you want to import a module called a inside a python script, the command to install it could be sometimes pip install b. Because the name of the stored package can varied from the python import name. To find how to install it the best is to get the pypi url of your package. You can googling the python error ModuleNotFoundError: No module named 'dgvd', it always show you the pypi url in top links.

The good practice in a project is to have a txt file called requirement.txt that you create in bash using this command:

pip freeze > requirement.txt

Then install all packages in once using:

pip install -r requirement.txt
Vincent Bénet
  • 1,212
  • 6
  • 20
  • 1
    PyPI is not the only package repository, it's just the most commonly used. – MattDMo Dec 17 '21 at 18:36
  • 1
    Its unfortunate your best method for this is googling. I find people mentioning module x somewhere when trying to find a way to do something, I run pip install x and get errors. Have to google to find out its actually called y. Then when I want to import it, I find actually called z when you import. – KeetsScrimalittle Feb 03 '23 at 19:38
0

For installing from zip simply use:

pip install *.zip

or specify the path directly:

pip install <path to .zip>
pip install ./my-archive.zip

Same applies for a tarball or any other format. It can be even a folder. However, it has to include a proper setup.py or other mechanism for pip to install it and pip has to support the packaging format (be it archive, networking protocol, version control system (git prefix), etc).

pip install ./my-folder
pip install ./
pip install .
pip install ..
etc

If, however, there is no setup.py present, you'll need to simply copy-paste the files somewhere where your project/module resides (or set PYTHONPATH or sys.path to that folder) to be able to import them. See this or this question for more.

Peter Badida
  • 11,310
  • 10
  • 44
  • 90