0

I am unable to import the pypi module (https://pypi.org/project/pypi/) into one of my python scripts.

I added the below line to my script to see which paths it's trying to get modules from:

print(sys.path)

Which shows the following:

`'/usr/local/lib/python3.5/dist-packages/', '/usr/lib/python3.5/dist-packages']

I have used pip to force the installation into those specific folders:

sudo pip3 install --upgrade --target=/usr/local/lib/python3.5/dist-packages/ pypi
sudo pip3 install --upgrade --target=/usr/lib/python3.5/dist-packages pypi

In both cases the installation is successful:

Collecting pypi
Installing collected packages: pypi
Successfully installed pypi-2.1

If I go check those folders, the package is there:

ls -lh /usr/lib/python3.5/dist-packages | grep pypi
drwxr-xr-x 2 root root 4.0K Apr 25 11:03 pypi-2.1.dist-info
drwxr-xr-x 2 root root 4.0K Apr 25 10:49 pypi-2.1-py3.5.egg-info

If I manually install the package I get something similar:

python3.5 ./setup.py install
running install
running build
running install_egg_info
Writing /usr/local/lib/python3.5/dist-packages/pypi-2.1.egg-info

Here is my script:

import sys
print(sys.path)
import pypi

And the error I get:

$ python3.5 myscrypt.py
[..., '/usr/local/lib/python3.5/dist-packages','/usr/lib/python3.5/dist-packages']
import pypi
ImportError: No module named 'pypi'

What am I missing to import pypi?

1 Answer 1

1

There are no importable modules or packages in the pypi package. The package was created to reserve the name so that evil hackers don't publish packages with this name.

What are really trying to install?

Sign up to request clarification or add additional context in comments.

4 Comments

I want to look for info on python packages: 1) scan .py files for import statements to identify imported modules 2) Retrieve the pypi package info (website/github URLs 3) Repeat those steps on hundreds of data-science related projects to build an inventory of most used packages, website URLs to go check them out etc.. A sort of package research/monitoring tool. As I came across this github.com/pypa/pip/issues/3354 which showed pypi.search({'name': query, 'summary': query}, 'or') so I thought pypi was a package. But I'm open to other solutions if you have
The previous line shows that pypi there is an XML-RPC client that connects to pypi.org.
So I guess they use some sort of XML API to read the pypi database and fetch info?
Ended up using their JSON API (warehouse.readthedocs.io/api-reference/json), very easy to consume with 2.python-requests.org/en/master

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.