1

I am trying to install a package I have written by running

 python setup.py install

whilst in the package directory. My folder structure is as follows:

package
-module
--__init__.py
--parent_class.py
--child_class.py
-setup.py

Here '-' denotes the folder level with package being the root directory.

When running the installation works as expected until:

Installed c:\users\me\appdata\local\continuum\anaconda3\lib\site- 
packages\package-0.1-py3.7.egg
Processing dependencies for package==0.1
Searching for json
Reading https://pypi.org/simple/json/
Couldn't find index page for 'json' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.org/simple/
No local packages or working download links found for json
error: Could not find suitable distribution for Requirement.parse('json')

I don't believe this is an issue with the json package installation as:

  1. I know I have it installed (I can run 'import json' in my env) and because if I remove it.
  2. If i remove 'json' from install_requires=['pandas', 'numpy', 'datetime', 'os', 'copy', 'json'] it will simply return the same error, this time with the 'copy' and then the 'os' package.

Thanks in advance

JDraper
  • 349
  • 2
  • 11

1 Answers1

1

I believe json is a built-in module in Python 2 and 3 (e.g., like open). Thus, it's usually included in all Python distributions (that is, anyone who has Python probably also has the json module).

Thus, you should be able to omit json from your requirements (while still importing it in your code). Since json is a built-in module, you can assume that anyone who has Python installed will also have json.

I found this question that is also about installing the json module. The second answer notes that minimal Python installs (e.g., python-minimal in Ubuntu) may not include json, however. You should note that the linked question concerns Python 2 and not 3.

Therefore, if a user lacks json on their system, they should be able to install it through their system's package manager (in Linux), and not pip. In Windows, I would assume that all Python installations will include built-in modules (though I don't know for certain). Regardless, if a user doesn't have json installed, then I think it's up to the user to install it.

The same applies to os, copy, and datetime. Only pandas and numpy need to be included in your requirements.

You can find a list of built-in modules (for Python 3) here. Again, the modules listed here are ones that are not hosted on pypi (thus not available through pip install ..., conda install ..., etc.), but ones that are usually included in all Python distributions.

As an aside: this is my first answer here. Please let me know if I can improve it.

emilh
  • 126
  • 3
  • 1
    Thanks, that worked (install worked). However the package is not found when I import it :/. – JDraper Jun 04 '20 at 18:39
  • 1
    I'm assuming you're trying to import `package` (as in your example from your question). You can't really do that, but you should be able to import `module`. Packaging conventions is a surprisingly complicated topic (at least, to me). You can take a look at [this tutorial](https://packaging.python.org/tutorials/packaging-projects/). Note that, towards the end, the example doesn't import the root directory (`packaging_tutorial`), but only the package/module inside. Consider renaming `module` to be `package`. Yes, this does mean that 2 folders have the same name, though this is what I do. – emilh Jun 04 '20 at 20:10
  • 1
    You can also look at [this question](https://stackoverflow.com/questions/15237806/python-modules-hierarchy-naming-convention). I format my projects with `my_package` as the root level folder and `my_package/my_package` (the actual package that contains `__init__.py`). I place `setup.py` and other packaging files in the root directory. Not sure if this is the best practice, but it seems to be used by several projects: [1](https://github.com/RaRe-Technologies/gensim), [2](https://github.com/numpy/numpy/tree/master/numpy). – emilh Jun 04 '20 at 20:20
  • Thanks for this additional advice, i'll check it out now :) – JDraper Jun 05 '20 at 07:40