No module named pipreqs.__main__; 'pipreqs' is a package and cannot be directly executed

Question:

I am trying to use pipreqs module to generate requirements text. But pipreqs is generating following error.

No module named pipreqs.__main__; 'pipreqs' is a package and cannot be directly executed

I’m using Visual Studio Code, and trying to use pipreqs by following command in Terminal.

python -m pipreqs [location/project]

I’ve already installed pipreqs and also updated pip. But still the problem remains. Is it a bug or am I doing it in the wrong way?

Asked By: carl

||

Answers:

That is a bug, but you can work around it by calling it as python -m pipreqs.pipreqs [location/project]

The reason of the the problem is that they didn’t include a __main__.py in the module that python expect when calling a package (a folder with an __init__.py and some other .py files if any) directly, which is like the if __name__=='__main__':... for modules, but need to be explicit for package.

Answered By: Copperfield