damnever / pigar

:coffee: A tool to generate requirements.txt for Python project, and more than that. (IT IS NOT A PACKAGE MANAGEMENT TOOL)

Home Page:https://damnever.github.io/pigar/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: 'NoneType' object has no attribute 'as_stream'

epistoteles opened this issue · comments

Describe the bug
No matter in which project or environment I run pigar, pigar generate terminates with the following error:

AttributeError: 'NoneType' object has no attribute 'as_stream'

Context (Environment)

  • OS: Ubuntu 22.04
  • Version of Python: 3.10.6
  • Version of pigar: 2.0.6

Additional context
Full error:

/home/korbinian/.local/lib/python3.10/site-packages/pigar/_vendor/pip/_vendor/distlib/database.py:173: UserWarning: Unable to read distribution at /home/korbinian/.local/lib/python3.10/site-packages/lightning_lite-1.8.0.post1.dist-info, perhaps due to bad metadata: '.*' not allowed for '>=' constraints
  for dist in self._yield_distributions():
/home/korbinian/.local/lib/python3.10/site-packages/pigar/_vendor/pip/_vendor/distlib/database.py:173: UserWarning: Unable to read distribution at /home/korbinian/.local/lib/python3.10/site-packages/pytorch_lightning-1.8.0.post1.dist-info, perhaps due to bad metadata: '.*' not allowed for '>=' constraints
  for dist in self._yield_distributions():
/home/korbinian/.local/lib/python3.10/site-packages/pigar/_vendor/pip/_vendor/distlib/database.py:173: UserWarning: Unable to read distribution at /usr/lib/python3/dist-packages/Send2Trash-1.8.1b0.dist-info, perhaps due to bad metadata: invalid version: "darwin"
  for dist in self._yield_distributions():
Traceback (most recent call last):
  File "/home/korbinian/.local/bin/pigar", line 8, in <module>
    sys.exit(main())
  File "/home/korbinian/.local/lib/python3.10/site-packages/pigar/__main__.py", line 479, in main
    cli()
  File "/home/korbinian/.local/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/korbinian/.local/lib/python3.10/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
  File "/home/korbinian/.local/lib/python3.10/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/korbinian/.local/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/korbinian/.local/lib/python3.10/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
  File "/home/korbinian/.local/lib/python3.10/site-packages/pigar/__main__.py", line 239, in generate
    analyzer = RequirementsAnalyzer(project_path)
  File "/home/korbinian/.local/lib/python3.10/site-packages/pigar/core.py", line 36, in __init__
    self._installed_dists = installed_distributions()
  File "/home/korbinian/.local/lib/python3.10/site-packages/pigar/dist.py", line 212, in installed_distributions
    req = FrozenRequirement.from_dist(distribution)
  File "/home/korbinian/.local/lib/python3.10/site-packages/pigar/dist.py", line 122, in from_dist
    installed_files = [
  File "/home/korbinian/.local/lib/python3.10/site-packages/pigar/dist.py", line 122, in <listcomp>
    installed_files = [
  File "/home/korbinian/.local/lib/python3.10/site-packages/pigar/_vendor/pip/_vendor/distlib/database.py", line 677, in list_installed_files
    for result in self._get_records():
  File "/home/korbinian/.local/lib/python3.10/site-packages/pigar/_vendor/pip/_vendor/distlib/database.py", line 596, in _get_records
    with contextlib.closing(r.as_stream()) as stream:
AttributeError: 'NoneType' object has no attribute 'as_stream'

When using pigar -l DEBUG, the last line printed before the error starts is

found local distribution: <PyNaCl 1.5.0  [nacl _sodium]  [/usr/lib/python3/dist-packages/nacl]>

(after a lot of other packages)

What is the output of pip freeze?

This is the output of pip freeze:

arrow==1.2.3
certifi==2022.12.7
charset-normalizer==3.1.0
click==8.1.3
cmake==3.26.3
codecarbon==2.1.4
filelock==3.11.0
fuzzywuzzy==0.18.0
idna==3.4
Jinja2==3.1.2
lit==16.0.1
MarkupSafe==2.1.2
mpmath==1.3.0
networkx==3.1
numpy==1.24.2
nvidia-cublas-cu11==11.10.3.66
nvidia-cuda-cupti-cu11==11.7.101
nvidia-cuda-nvrtc-cu11==11.7.99
nvidia-cuda-runtime-cu11==11.7.99
nvidia-cudnn-cu11==8.5.0.96
nvidia-cufft-cu11==10.9.0.58
nvidia-curand-cu11==10.2.10.91
nvidia-cusolver-cu11==11.4.0.1
nvidia-cusparse-cu11==11.7.4.91
nvidia-nccl-cu11==2.14.3
nvidia-nvtx-cu11==11.7.91
pandas==2.0.1
psutil==5.9.5
py-cpuinfo==9.0.0
pynvml==11.5.0
python-dateutil==2.8.2
pytz==2023.3
requests==2.29.0
scipy==1.10.1
six==1.16.0
sympy==1.11.1
torch==2.0.0
triton==2.0.0
typing_extensions==4.5.0
tzdata==2023.3
urllib3==1.26.15
OS: Ubuntu 22.04
Version of Python: 3.10.5
Version of pigar: 2.0.5

anyio==3.6.2
argon2-cffi==21.3.0
argon2-cffi-bindings==21.2.0
arrow==1.2.3
asttokens==2.2.1
attrs==23.1.0
autograd==1.5
autograd-gamma==0.5.0
Babel==2.12.1
backcall==0.2.0
beautifulsoup4==4.12.2
bleach==6.0.0
Brotli==1.0.9
certifi==2023.5.7
cffi==1.15.1
click==8.1.3
click-plugins==1.1.1
cligj==0.7.2
colorama==0.4.6
comm==0.1.3
contourpy==1.0.7
cssselect2==0.7.0
cycler==0.11.0
debugpy==1.6.7
decorator==5.1.1
defusedxml==0.7.1
docutils==0.17.1
docxcompose==1.4.0
entrypoints==0.4
et-xmlfile==1.1.0
executing==1.2.0
fastjsonschema==2.17.1
Fiona==1.9.4.post1
fonttools==4.39.4
fqdn==1.5.1
future==0.18.3
geopandas==0.12.2
greenlet==2.0.2
h3==3.7.6
html5lib==1.1
idna==3.4
imageio==2.29.0
ipyevents==2.0.1
ipykernel==6.20.2
ipympl==0.9.3
ipython==8.8.0
ipython-genutils==0.2.0
ipywidgets==8.0.6
isoduration==20.11.0
jedi==0.18.2
Jinja2==3.1.2
joblib==1.2.0
jsonpointer==2.3
jsonschema==4.17.3
jupyter-console==6.4.4
jupyter-events==0.6.3
jupyter_client==7.4.9
jupyter_core==5.1.5
jupyter_server==2.5.0
jupyter_server_terminals==0.4.4
jupyterlab-pygments==0.2.2
jupyterlab-widgets==3.0.7
kaleido==0.2.1
kiwisolver==1.4.4
llvmlite==0.39.1
lxml==4.9.2
MarkupSafe==2.1.2
matplotlib==3.6.3
matplotlib-inline==0.1.6
mistune==2.0.5
mplcursors==0.5.2
nbclassic==1.0.0
nbclient==0.7.4
nbconvert==7.2.10
nbformat==5.7.3
nest-asyncio==1.5.6
networkx==3.1
notebook==6.5.4
notebook_shim==0.2.3
numba==0.56.4
numpy==1.23.5
openpyxl==3.0.10
packaging==23.1
pandas==1.5.3
pandocfilters==1.5.0
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.5.0
platformdirs==3.5.1
plotly==5.13.1
prometheus-client==0.16.0
prompt-toolkit==3.0.38
psutil==5.9.5
ptyprocess==0.7.0
pure-eval==0.2.2
pybaselines==1.0.0
pycparser==2.21
pydyf==0.6.0
Pygments==2.15.1
pyparsing==3.0.9
pyphen==0.14.0
pyproj==3.4.1
pyrsistent==0.19.3
python-dateutil==2.8.2
python-docx==0.8.11
python-dotenv==0.21.1
python-json-logger==2.0.7
pytz==2023.3
PyWavelets==1.4.1
PyYAML==6.0
pyzmq==25.0.2
qtconsole==5.4.3
QtPy==2.3.1
reliability==0.8.7
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
scikit-gstat==1.0.10
scikit-image==0.19.3
scikit-learn==1.2.2
scipy==1.10.1
seaborn==0.12.2
Send2Trash==1.8.2
shapely==2.0.1
six==1.16.0
sniffio==1.3.0
soupsieve==2.4.1
SQLAlchemy==1.4.48
stack-data==0.6.2
tenacity==8.2.2
terminado==0.17.1
threadpoolctl==3.1.0
tifffile==2023.4.12
timezonefinder==6.1.1
tinycss2==1.2.1
tornado==6.3.2
tqdm==4.65.0
traitlets==5.9.0
uri-template==1.2.0
wcwidth==0.2.6
weasyprint==57.2
webcolors==1.13
webencodings==0.5.1
websocket-client==1.5.2
widgetsnbextension==4.0.7
windrose==1.8.1
zopfli==0.2.2

I am unable to reproduce this issue.

Please try this to see if the error persists:

pip uninstall pigar
pip install git+https://github.com/damnever/pigar.git@fix/153

I am unable to reproduce this issue.

Please try this to see if the error persists:

pip uninstall pigar
pip install git+https://github.com/damnever/pigar.git@fix/153

Installed pigar today (thanks!): same issue, fixed by your link

A new release is now available, give it a try: pip install pigar==2.0.7.