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
Did you create a virtual environment? You should not add packages to the system python.
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
You need to activate the virtual environment and use pip fom inside the virtual environment.
Can you please provide how to activate pip in the virtual environment?
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.
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