pyre-check icon indicating copy to clipboard operation
pyre-check copied to clipboard

Pyre is unable to find any module

Open baptiste0928 opened this issue 3 years ago • 5 comments

Hello ! :wave:

I installed Pyre on one of my projects in order to test it, but it is unable to find the modules I import, even native Python modules. Here is an example of what the pyre command returns:

core/rethink.py:1:0 Undefined import [21]: Could not find a module corresponding to import `asyncio`.
core/rethink.py:2:0 Undefined import [21]: Could not find a module corresponding to import `os`.
core/rethink.py:3:0 Undefined import [21]: Could not find a module corresponding to import `typing`.
core/rethink.py:5:0 Undefined import [21]: Could not find a module corresponding to import `loguru`.
core/rethink.py:6:0 Undefined import [21]: Could not find a module corresponding to import `rethinkdb`.
core/rethink.py:7:0 Undefined import [21]: Could not find a module corresponding to import `rethinkdb.net`.
core/rethink.py:10:0 Analysis failure [30]: Terminating analysis because type `list` is not defined.
core/rethink.py:36:4 Analysis failure [30]: Terminating analysis because type `list` is not defined.
core/rethink.py:43:4 Analysis failure [30]: Terminating analysis because type `list` is not defined.

Pyre seems correctly installed (in a venv) and I added this venv to the search_path. Here is my configuration file (I replaced the project path):

{
  "binary": "path/to/project/venv/bin/pyre.bin",
  "source_directories": [
    "core"
  ],
  "search_path": "path/to/project/venv",
  "taint_models_path": "path/to/project/venv/lib",
  "typeshed": "path/to/project/venv/lib/pyre_check/typeshed"
}

I use Python 3.8.6 under Manjaro Linux and the following version of Pyre : image

Thank you in advance for your answers ! :smile:

baptiste0928 avatar Dec 07 '20 18:12 baptiste0928

I can confirm this issue:

pyre --version
Client version: internal-dev
{
  "binary": ".tox/py38/bin/pyre.bin",
  "source_directories": [
    "./src
  ],
  "search_path": [
    ".tox/py38/lib/python3.8",
    "venv"
  ],
  "taint_models_path": ".tox/py38/lib"
}

ƛ Found 177 type errors! And then mentions every module imported at some point.

theBigGron avatar Feb 03 '21 23:02 theBigGron

@theBigGron @baptiste0928

Thanks for reporting. I'm curious if either of you are seeing any warnings related to typeshed?

MaggieMoss avatar Mar 19 '21 18:03 MaggieMoss

@MaggieMoss how to print more warnings? Im having same issue in a new conda environment Im teting pyre on (for a little large project I want to add typing).

In particular

ƛ Failed to initialize file monitor: Could not find a watchman directory from the current directory `/home/tyoc213/PycharmProjects/core`
ƛ Found 1400 type errors!
../aprov.py:87:18 Unbound name [10]: Name `traceback` is used but not defined in the current scope.
../auto-aprov.py:56:35 Undefined attribute [16]: `datetime.date` has no attribute `days`.
...................................
app/adm.py:6:0 Undefined import [21]: Could not find a module corresponding to import `flask_admin`.
app/adm.py:7:0 Undefined import [21]: Could not find a module corresponding to import `flask_admin.actions`.
app/adm.py:8:0 Undefined import [21]: Could not find a module corresponding to import `flask_admin.contrib.sqla`.
app/adm.py:24:0 Undefined import [21]: Could not find a module corresponding to import `app.models.AcModels`.
app/adm.py:25:0 Undefined import [21]: Could not find a module corresponding to import `app.models.BaModels`.
app/adm.py:26:0 Undefined import [21]: Could not find a module corresponding to import `app.models.ByModels`.
app/adm.py:27:0 Undefined import [21]: Could not find a module corresponding to import `app.models.CModels`.
app/adm.py:28:0 Undefined import [21]: Could not find a module corresponding to import `app.models.ColRModels`.
...................................
../migrations/env.py:1:0 Undefined import [21]: Could not find a module corresponding to import `alembic`.
../migrations/env.py:2:0 Undefined import [21]: Could not find a module corresponding to import `sqlalchemy`.
../migrations/versions/071a5c315559_.py:13:0 Undefined import [21]: Could not find a module corresponding to import `alembic`.
../migrations/versions/071a5c315559_.py:14:0 Undefined import [21]: Could not find a module corresponding to import `sqlalchemy`.
../migrations/versions/11e0b1fabe54_.py:13:0 Undefined import [21]: Could not find a module corresponding to import `alembic`.
../migrations/versions/11e0b1fabe54_.py:14:0 Undefined import [21]: Could not find a module corresponding to import `sqlalchemy`.
../migrations/versions/1a311ed29e17_.py:13:0 Undefined import [21]: Could not find a module corresponding to import `alembic`.
../migrations/versions/1a311ed29e17_.py:14:0 Undefined import [21]: Could not find a module corresponding to import `sqlalchemy`.
../migrations/versions/1eb84b8944f6_.py:13:0 Undefined import [21]: Could not find a module corresponding to import `alembic`.
../migrations/versions/1eb84b8944f6_.py:14:0 Undefined import [21]: Could not find a module corresponding to import `sqlalchemy`.
../migrations/versions/1fc6250d581d_.py:13:0 Undefined import [21]: Could not find a module corresponding to import `alembic`.
../migrations/versions/1fc6250d581d_.py:14:0 Undefined import [21]: Could not find a module corresponding to import `sqlalchemy`.
..............
aly.py:101:4 Incompatible return type [7]: Expected `bool` but got implicit return value of `None`.
$ pyre --version
Binary version: 8ebc243adc0a7e2bcd9823da34216724146c2de2
Client version: internal-dev

Also is not finding local/app imports like app.models.

Which Im sure I alchemy and sql alchemy and friends on the conda env :), for example, I can import flask_admin

image

tyoc213 avatar Sep 12 '21 03:09 tyoc213

I found this to work:

pyre --search-path $(python -c 'import site; print(site.getsitepackages()[0])')

This basically asks python where the installed packages are and tells it to pyre. My .pyre_configuration is just this:

{
  "source_directories": [
    "."
  ],
  "exclude": [
    ".*build/.*"
  ]
}

tmke8 avatar Oct 02 '21 10:10 tmke8

Still an issue.

pyre --version Client version: 0.9.19

.pyre_configuration:

{
  "site_package_search_strategy": "pep561",
  "source_directories": [ "." ],
  "search_path": [ "venv" ],
  "exclude": [ ".*/venv/.*" ]
}

pyre check:

foo.py:1:0 Undefined import [21]: Could not find a module corresponding to import os. backend/bar.py:9:0 Analysis failure [30]: Terminating analysis because type list is not defined.

The workaround suggested just above does not help:

(venv) $ pyre --search-path $(python -c 'import site; print(site.getsitepackages()[0])')
ƛ No watchman binary found. 
To enable pyre incremental, you can install watchman: https://facebook.github.io/watchman/docs/install
ƛ Defaulting to non-incremental check.
ƛ Found 176 type errors!
app.py:1:0 Undefined import [21]: Could not find a module corresponding to import `flask`.
app.py:3:0 Undefined import [21]: Could not find a module corresponding to import `flask_restful`.
app.py:4:0 Undefined import [21]: Could not find a module corresponding to import `flask_swagger_ui`.
aws_conf.py:1:0 Undefined import [21]: Could not find a module corresponding to import `os`.
aws_ssm_manager.py:1:0 Undefined import [21]: Could not find a module corresponding to import `boto3`.
backend/launch_server.py:9:0 Analysis failure [30]: Terminating analysis because type `list` is not defined.
[...]

python version — 3.10.12

ulidtko avatar Mar 29 '24 17:03 ulidtko