Trouble importing python packages Visual Studio Code - python

I am on Windows 10, running python 3.8.5 and have tried installing PyPDF2 using pip. I've uninstalled and reinstalled several times using these two commands:
"python -m pip install pypdf2"
"py -3 -m pip install pypdf2"
I did this through Visual Studio code being run as my user, as well as the command prompt run as an administrator. The install goes well but I get the error, "Import 'PyPDF2' could not be resolved."
I figure this is due to the file path to the installed package not being included in the PATH system environment variable. So I used "python -m pip show pypdf2" to find the install location:
"c:\users*username*\appdata\local\programs\python\python38\lib\site-packages"
So I added:
"c:\users*username*\appdata\local\programs\python\python38\lib\site-packages\PyPDF2" to my PATH environment variable for both user and system, as well as the PYTHONPATH variable.
After such actions I restarted VS Code, which again is using the python 3.8.5 environment, and still the import could not be resolved.
What am I missing? Any assistance would be greatly appreciated.

I am using python 3.9.6. But when I typed like this in command prompt,
"pip install pypdf2"
it worked for me. Try like this sometimes it'll work.

Related

Python virtualenvironment can't find packages

When i run python -m pip install {package} inside the virtual environment i created with python -m venv env the package is installed inside the env/Lib folder, however when i want to use the package the venv interpreter can't find the package. For example I installed ipykernel, but when I try to run a cell inside Visual Studio code I get a message saying I have to install ipykernel and even if I accept this message and install it again I keep getting the message that I have to install ipykernel.
I already tried deleting all my versions of python and reinstalling python I also tried to set the global target of python to my library folder python pip config set global.target {path to venv Library}
I am using python 3.8.0 which is the only python installed on my pc. I also have windows 10 and my editor is visual studio code. Please help.
If I run python -m pip freeze requirements inside my enviroment nothing happens. When I run python -m pip freeze requirements outside my environment I get a list of all installed packages
Please enter the command "pip show ipykernel" in the terminal of VS Code to check whether this module is included in this environment. (It checks whether the installation location of the module is consistent with the Python environment displayed in the lower left corner of VSCode.)
If the terminal shows that there is no such module, please open a new VS Code terminal(shortcut key: Ctrl+Shift+`), it will automatically enter the environment displayed in the lower left corner of VSCode.

Python: Scripts folder is blank and no pip files

Installed python installed on system of version 3.8.5 but there is an error with pip. pip is not installed
Below is the path
C:\Users\Comp1\AppData\Local\Programs\Python\Python38-32\Scripts
Found some results and tried running python get-pip.py from cmd but didn't work.
Also checked PATH and was correct
After using pip command in cmd it gives "pip is not recoganized"
Please let me know how can I fix this issue.

VS code not recognize the Python package I installed on my Mac

I tried to run a python script file on Visual Studio. But the terminal keep pop up saying that I don't have the package installed... I don't know what is going on. I installed Python through homebrew and install all the package through pip3. I even find the path for all the package I have installed, and it's still not working.. I switched between multiple interpreter, and none of them worked, all said my package is not installed.. but it's clearly my package is installed... I even create a new py file to run pandas, and it worked.. Can someone help me with this? This is driving me crazy..
It just because you had chosen the wrong python environment in VSCode.
You said you had created a python file to run pandas and it worked. This means you had installed the package 'pandas' and it worked. But you haven't chosen this environment in your VSCode.
In the terminal:
By command "pip3 --version" to check which pip you are using.
By command "python3" -> "import sys; sys.executable" to check which python you are using.
By command "python3" -> "import sys; sys.path" to check which 'site-package' the interpreter searching for.
From your description, you are using the pip which under '/usr/local', install the packages under '/usr/local/lib/python3.7/site-packages', using python interpreter of '/usr/local/bin/python3'. This is the default python interpreter because of the system environment variables settings. But in VSCode you haven't chosen this environment.
Solution:
Choose an environment or create a virtual environment(recommend). Activate the environment(Ctrl+Shift+`), by the command 'pip3 --version' to check which pip3 you are using, then install the package you want to import.
If you installed python via homebrew try using homebrew to install pandas instead of pip. I've seen things before that they get linked. I would just recommend using pip to uninstall pandas first so there is only package.

discord py in Visual Studio Code not detecting extension

I installed discord.py with the voice and without in the visual studio code terminal because in my cmd it doesn't detect pip like a command (I'm on windows). I've tried too in the python terminal but it doesnt detetect pip like a command.
Please help.
Pip is installed, it's just not installed as a command, and that's on purpose. What you want to do is create a virtual environment and then install into there by activating the environment and then using python -m pip.

Visual Studio 2019 install Python3.7 Package, geting TLS/SSL problem

I was trying to install Python3.7 package inside visual studio however I keep getting
"pip is configured with locations that require TLS/SSL, however the SSL module in Python is not available." issues, no matter what package.
The OS is windows I also tried to use CMD to pip, it seems package can be successfully installed, but it does not reflect in Visual Studio. Tried reinstall Python component in Visual Studio but with no luck.
The visual studio does have both 3.6 and 3.7 and I have Anaconda. Install package works with 3.6 in VS but not for 3.7. I really don't know where else to look for problem, could be some path configuration problem, environment variable problem?
I experienced similar symptoms and was able to find a suitable workaround.
Background:
Fresh install of Visual Studio 2019 in May 2019, no previous install of anaconda, etc. I could add pypi packages in 3.6 conda environments, but not 3.7. Attempts to install from both VS2019 and powershell would result in the ssl module error you describe.
Workaround: I was able to work around this by running pip install from the conda command prompt.
To do this, I navigated to the conda folder, which for me was at:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\Microsoft\Python\Miniconda\Miniconda3-x64\Scripts.
I could run conda.exe but it errors out saying the environment isn't set up. If you modify your path to include the above directory plus several other parent and subs (miniconda3-x64 root, library, library/bin; condabin; maybe others) the error message will actually give you helpful instructions to run conda init cmd.exe or something similar to prepare your environment. You can run this for powershell as well. I ran this as admin. Close your shell and reopen, and then you can run conda activate <environment>. Once in the conda shell, I could run pip install <package> and it all worked fine, and was reflected in VS2019 view immediately.
TL;DR: Navigate to the folder where conda.exe lives; run conda init cmd.exe as admin; reopen cmd.exe; run conda activate <environment name>; run pip install <package name>; run conda deactivate; return to VS2019, verify, rejoice.

Categories

Resources