question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Libraries from the local folder are not imported

See original GitHub issue

Describe the bug With the latest version (0.16.0.0) the libraries from the local folder __pypackages__ are not imported.

How to reproduce

python3 -m pip install --user pythonloc python3 -m pipx ensurepath piploc install flask pipx run --pypackages flask

Traceback

Traceback (most recent call last):
  File "/home/martin/workspace/flask-desktop/__pypackages__/3.8/lib/bin/flask", line 5, in <module>
    from flask.cli import main
ModuleNotFoundError: No module named 'flask'

Expected behavior

It should show the following:

Usage: flask [OPTIONS] COMMAND [ARGS]...

  A general utility script for Flask applications.

  Provides commands from Flask, extensions, and the application. Loads the
  application defined in the FLASK_APP environment variable, or from a
  wsgi.py file. Setting the FLASK_ENV environment variable to 'development'
  will enable debug mode.

    $ export FLASK_APP=hello.py
    $ export FLASK_ENV=development
    $ flask run

Options:
  --version  Show the flask version
  --help     Show this message and exit.

Commands:
  db      Perform database migrations.
  lint    Lint and check code style with 'flake8' and 'isort' recursively.
  ps      Perform postgres operations.
  roles   Role commands.
  routes  Show the routes for the app.
  run     Run a development server.
  shell   Run a shell in the app context.
  users   User commands.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
itsayellowcommented, Feb 14, 2021

Ohhh I see what’s happening. One part of our code run_pypackage_bin adds the __pypackages__ path to env variable PYTHONPATH, and then exec_app uses _fix_subprocess_env to remove PYTHONPATH before running the code.

Here is the helpful comment in the code:

    # Remove PYTHONPATH because some platforms (macOS with Homebrew) add pipx
    #   directories to it, and can make it appear to venvs as though pipx
    #   dependencies are in the venv path (#233)

Hmmm. Seems we have a fix in conflict with the operation of a feature. (See #233)

0reactions
mmozoscommented, Feb 14, 2021

@mmozos just a guess looking at the code: Have you changed python versions lately? Could pipx be running from a different python version than the flask you installed?

It looks like our code adds __pypackages_/<python_version>/lib to env variable PYTHON_PATH before running your flask app. pipx determines <python_version> by using its own python version. If that’s different than what you have for flask (3.8) then that might explain why it isn’t working.

EDIT: Hmm this may not explain anything. It looks like our code should use the same root path for both the console script binary and the libraries. So if it finds the console script I’m not sure why it isn’t adding the right path for the supporting packages.

I am using the only one and the default python version that comes in Linux Mint 20.04.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Import library from local folder without editing system path
Importing the library through pip install; Moving folders into site-packages; Editing the system PATH. So far the answers I've seen on stack ...
Read more >
Change where your music files are stored on Mac
Change where imported files are stored on your Mac, choose Music > Settings, then click Files. · Consolidate your files in the Music...
Read more >
Installing Libraries | Arduino Documentation
Importing a .zip Library. Libraries are often distributed as a ZIP file or folder. The name of the folder is the name of...
Read more >
Importing and Managing Media - LWKS - Video Editing Software
2. Click on the Local Files option under 'Libraries'. 3. Click on the Places dropdown arrow to navigate to the drive and folder...
Read more >
Python – Import module from different directory - GeeksforGeeks
Let's suppose, to import how to import file in Python, we have two different folders, one contains main.py which is our main Python...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found