damnever / pigar

:coffee: A tool to generate requirements.txt for Python project, and more than that. (IT IS NOT A PACKAGE MANAGEMENT TOOL)
https://damnever.github.io/pigar/
BSD 3-Clause "New" or "Revised" License
1.64k stars 89 forks source link

pigar cannot find the package name #221

Open ManiAm opened 1 week ago

ManiAm commented 1 week ago

I have this import in one of the files,

try:
    from bs4 import BeautifulSoup
    bs4_support = True
except:
    bs4_support = False

Invoke pigar with:

pigar generate --auto-select --question-answer no

However it cannot find the package name 'beautifulsoup4'.

Same is true for,

try:
    import jinja2
    jinja_support = True
except ImportError:
    jinja_support = False

I am using rhel 8.9 and python 3.12.0.

damnever commented 1 week ago
try:
  import bs4
except ImportError:
  ...

this makes pigar consider bs4 as optional, pigar will simply ignore it if it is not installed in the local environment. This behavior might be disabled via an additional option, but I don't have strong opinions on this.

If you want to resolve this, you can either remove the try ... except ImportError ... block or install bs4 in the local environment manually.

ManiAm commented 1 week ago

or install bs4 in the local environment manually.

beautifulsoup4 is installed on my local virtual env.

pip3 show beautifulsoup4
Name: beautifulsoup4
Version: 4.12.3
Summary: Screen-scraping library
Home-page: https://www.crummy.com/software/BeautifulSoup/bs4/
Author: 
Author-email: Leonard Richardson <leonardr@segfault.org>
License: MIT License
Location: /auto/panini-projs/fabric/spitfire/CATS/python3.12/lib/python3.12/site-packages
Requires: soupsieve
Required-by: nbconvert

Link: https://pypi.org/project/beautifulsoup4/

damnever commented 1 week ago

The current limitation is that both need to be in the same Python environment, whether it's the system global environment or a virtual one.