Python Forum
Python package not seen in VSCode
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python package not seen in VSCode
#1
Good afternoon,

I am new to coding, Linux and VSCode.

System - Linux Mint 21.1
Using VSCode to write script
Trying to import Pandas, Numpy, Ta-Lib and others package example: Import numpy
Error:
Error : Import "numpy" could not be resolved Pylance (reportMissingImports)
I tried to install Numpy with with pip, here is the end result:

pip install numpy
Output:
Defaulting to user installation because normal site-packages is not writeable Collecting numpy Using cached numpy-1.24.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (17.3 MB) Installing collected packages: numpy WARNING: The scripts f2py, f2py3 and f2py3.10 are installed in '/home/user/.local/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed numpy-1.24.2
Why and how can I fixed this?

Thanks
Larz60+ write Mar-06-2023, 08:28 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
fixed for you this time, please use BBCode tags on future posts.
Reply
#2
Did you create a virtual environment? You should not add packages to the system python.
Reply
#3
I just created a venv following the instruction on VSCode tutorial and nothing change except that a .venv file has been added to my "project file".
I also looked at Python Interpreter and selected the new .venv option that is now available.
But when trying to import a package, example Numpy, it is still gray and the "Import "numpy" could not be resolved Pylance (reportMissingImports)" is still there.

Screenshot here:
https://ibb.co/QYJv71N
Reply
#4
You need to activate the virtual environment and use pip fom inside the virtual environment.
Reply
#5
Can you please provide how to activate pip in the virtual environment?
Reply
#6
From a shell, you make a virtual environment and activate like this:
Output:
dean@ubuntu:~$ python3 -m venv demo dean@ubuntu:~$ ls Desktop Downloads Music Projects snap demo Documents git Pictures Public Templates Videos dean@ubuntu:~$ source demo/bin/activate (demo) dean@ubuntu:
Notice the prompt changed to let me know the shell is running in in a virtual Python environment.


In VSCode you set the python interpreter.
Open VSCode and open the command pallet.
Select Python: Select Interpreter
A dialog will pop up with choices. If your virtual environment is one of the choices, select it. If not, select find and browse for your interpreter. In the example above, my interpreter is demo/bin/python.

After selecitng a python interpreter open a new terminal the prompt will contain the virtual environment name.
Reply
#7
Good, it works for the installed of Numpy and Pandas dependency.

But when trying to install Ta-Lib this is the output:

Output:
(.venv) sh-5.1$ pip install TA-Lib Collecting TA-Lib Using cached TA-Lib-0.4.25.tar.gz (271 kB) Installing build dependencies ... done Getting requirements to build wheel ... done Installing backend dependencies ... done Preparing metadata (pyproject.toml) ... done Requirement already satisfied: numpy in ./.venv/lib/python3.10/site-packages (from TA-Lib) (1.24.2) Building wheels for collected packages: TA-Lib
Error:
Building wheel for TA-Lib (pyproject.toml) ... error error: subprocess-exited-with-error × Building wheel for TA-Lib (pyproject.toml) did not run successfully. │ exit code: 1 ╰─> [27 lines of output] <string>:77: UserWarning: Cannot find ta-lib library, installation may fail. [error] [/output] running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-cpython-310 creating build/lib.linux-x86_64-cpython-310/talib copying talib/test_stream.py -> build/lib.linux-x86_64-cpython-310/talib copying talib/test_polars.py -> build/lib.linux-x86_64-cpython-310/talib copying talib/test_pandas.py -> build/lib.linux-x86_64-cpython-310/talib copying talib/test_func.py -> build/lib.linux-x86_64-cpython-310/talib copying talib/test_data.py -> build/lib.linux-x86_64-cpython-310/talib copying talib/test_abstract.py -> build/lib.linux-x86_64-cpython-310/talib copying talib/stream.py -> build/lib.linux-x86_64-cpython-310/talib copying talib/deprecated.py -> build/lib.linux-x86_64-cpython-310/talib copying talib/abstract.py -> build/lib.linux-x86_64-cpython-310/talib copying talib/__init__.py -> build/lib.linux-x86_64-cpython-310/talib running build_ext building 'talib._ta_lib' extension creating build/temp.linux-x86_64-cpython-310 creating build/temp.linux-x86_64-cpython-310/talib x86_64-unknown-linux-gnu-gcc -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -fno-omit-frame-pointer -fPIC -I/usr/include -I/usr/local/include -I/opt/include -I/opt/local/include -I/opt/homebrew/include -I/opt/homebrew/opt/ta-lib/include -I/tmp/pip-build-env-wicutnul/normal/lib/python3.10/site-packages/numpy/core/include -I/home/fmc-crypto/Desktop/Project/.venv/include -I/usr/include/python3.10 -I/usr/include/x86_64-linux-gnu/python3.10 -c talib/_ta_lib.c -o build/temp.linux-x86_64-cpython-310/talib/_ta_lib.o [/output] [error] talib/_ta_lib.c:747:10: fatal error: ta-lib/ta_defs.h: No such file or directory 747 | #include "ta-lib/ta_defs.h" | ^~~~~~~~~~~~~~~~~~ compilation terminated. error: command '/usr/bin/x86_64-unknown-linux-gnu-gcc' failed with exit code 1 [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for TA-Lib Failed to build TA-Lib ERROR: Could not build wheels for TA-Lib, which is required to install pyproject.toml-based projects (.venv) sh-5.1$ sudo apt-get -y install gcc build-essential sh: sudo: command not found
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to run utilities from a Python package? LugosisGhost 1 441 Dec-27-2023, 12:00 PM
Last Post: Larz60+
  Python on VSCode GiBandoleiro 1 482 Nov-01-2023, 03:35 PM
Last Post: deanhystad
  I use VsCode with Python and it currently won't let me run any code NordicMonkey 2 1,523 Sep-18-2022, 08:42 PM
Last Post: Larz60+
Photo A humble VsCode Python Snippets 2.0 medlexo 6 2,410 Jan-03-2022, 08:54 PM
Last Post: medlexo
  Math Package in python Uma 1 1,495 Dec-12-2021, 02:01 PM
Last Post: jefsummers
  VSCode Setup and configuring to run with Python apollo 2 3,074 Jan-13-2021, 04:55 PM
Last Post: jefsummers
  Python IDE doesn't see opencv-python package on my Jetson Nano sadhaonnisa 1 3,351 Oct-11-2020, 01:04 AM
Last Post: Larz60+
  Help needed for a python package keysson 1 2,220 Sep-02-2020, 03:37 AM
Last Post: Larz60+
  Installing a python package using pip anthonymoss78 0 1,820 Jul-14-2020, 01:52 PM
Last Post: anthonymoss78
  Python package as installable Prabakaran141 0 1,503 Mar-10-2020, 10:07 AM
Last Post: Prabakaran141

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020