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

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.

Related

Upgrade python to 3.10 in windows; Do I have to reinstall all site-packages manually?

I have in windows 10 64 bit installed python 3.9 with site-packages. I would like to install python 3.10.2 on windows 10 64 bit and find a way to install packages automatically in python 3.10.2, the same ones I currently have installed in python 3.9. I am also interested in the answer to this question for windows 11 64 bit.
I upgraded to python 3.10.2 in windows 10 64 bit. To properly install the packages, install the appropriate version of the Microsoft Visual C++ compiler if necessary. Details can be read https://wiki.python.org/moin/WindowsCompilers . With the upgrade to python 3.10.2 from 3.9, it turned out that I had to do it, due to errors that are appearing during the installation of the packages. Before the installing python 3.10.2, type and execute the following command in the windows command prompt:
pip freeze > reqs.txt
This command writes to the reqs.txt file the names of all installed packages in the version suitable for pip. If you run the command prompt with administrator privileges, the reqs.txt file will be saved in the directory C:\WINDOWS\system32.
Then, after the installing of python 3.10.2 and the adding it to the paths in PATH, with the help of the command prompt you need to issue the command:
pip install -r reqs.txt
This will start the installing of the packages in the same versions as for python 3.9. If problems occur, e.g. an installation error appears during the installation of lxml, then you can remove from the regs.txt file the entry with the name of the package whose installation is causing the problem and then install it manually. To edit the reqs.txt file you need the administrator privileges. The easiest way is to run the command prompt in the administrator mode, type reqs.txt and click Enter to edit it.
I decided later to update the missing packages to the latest version, because I suspected that with python 3.10.2 older versions were not compatible.
This means that when upgrading to python 3.10.2 it is worth asking yourself whether it is better to upgrade for all packages. To do this, you can generate the list of the outdated packages using the command:
pip list –-outdated
After the printing of the list in the command prompt, you can upgrade the outdated packages using the command:
pip install --upgrade <package-name>
This can be automated by the editing of the reqs.txt file and the changing of the mark == to > which will speed up the upgrade. The mark > should only be changed for the outdated packages or you will get an error: "Could not find a version that satisfies the requirement ... ".
Supplement to virtual environments:
When you enter a virtual environment directory (in the windows command prompt):, such as D:\python_projects\data_visualization\env\Scripts, type activate to activate it. Then create the reqs.txt file analogous to the description above. Then, copy the file to a temporary directory. After this delete the virtual environment, e.g. using the windows explorator by the deleting of the contents of the env directory. Then, using the version of python in windows of our choice, create a virtual environment using the env directory (see: https://docs.python.org/3/library/venv.html). Copy the regs.txt file to the newly created D:\python_projects\data_visualization\env\Scripts directory. Install site-packages with the support of the regs.txt file as described above.
No you need not reinstall python packages.
conda create --name project-env python=3.x
You can also look at an alternative method to install python versions Install python version

Trouble importing python packages Visual Studio Code

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.

Visual Studio Code, Anaconda Virtual Environment, specific projects?

can anyone help me understand using conda environment with visual studio code? I had activate the virtual environment (imageprocessing) with this:
conda activate imageprocessing
and the terminal seem to have been on virtual environment, so there's look like no problem with the PATH, it looks like this.
(imageprocessing) ../users/[project_folder_somewhere]
But when I open visual studio code and activate the kernel used for opening Notebooks there, exactly with the python from imageprocessing virtual environment, I keep needed to install the previously forged library, for example, Pillow. Which part that doesn't work out? Did I install Pillow package redundantly if I keep doing this? Does visual code doesn't integrated that well with conda even though it has been connected through the path? I used this feature for opening .ipynb files on Visual Studio Code because browser-based Jupyter Notebooks are too slow and messy directory than if using this (or so I thought?).
In VS Code, when we use different python environments, the locations where the modules are installed are different. Therefore, we need to be clear which python environment we are currently using. (We could check it with the command "python --version" in the VS Code terminal.)
When we use the conda environment, it comes with python, so we can use "pip" to install modules, or "conda" to install modules. The modules it installs are stored in: "...\anaconda3\envs\conda-name\lib\site-packages".
The command "pip show pillow" checks the installation position of the module:
In addition, after the installation is complete, it still shows that the module cannot be found. I noticed that there is a problem with the file name here. We need to rename "PIL" to "pillow", or use "import PIL"
Reference: conda-environment in VS Code.
Add:

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.

Categories

Resources