I'm on VSC and I had to change the python version using the different environments, now when I import modules VSC says they aren't installed - import

I needed to change to a different python version because one of my imports had randint in it from random and my lanky python 3.8.10 doesn't like it.
I'm installing my modules for my discord bot as I would usually do, but now it hits me with
Import "discord" could not be resolved
(same for all other modules I've tried importing)
...
Using pip freeze I can see it's there, it's installed, but VSC refuses to recognise it.
I've tried going back to my original 3.8.10, and it works perfectly, it just means I need to remove the faulty import and then my code won't work.
I've tried using all the other interpreters but still, nothing happens. Only on 3.8.10
Any help?

Related

"Import "pyautogui" could not be resolved from source" while having pyautogui installed on VS Code

I'm having trouble right now with PyAutoGUI. I have installed it in:
C:\msys64\mingw64\lib\python3.9\site-packages
but VS Code doesn't seem to recognize it.
I get this message:
Import "pyautogui" could not be resolved from source
I've already tried reinstalling everything, set paths and verify installations.
Use Ctrl+Shift+P --> Python:Select Interpreter to select the correct interpreter.
If there are multiple python versions on your machine, you need to use the one that has the pyautogui package installed.
You can check the current interpreter path with the following code.
import sys
print(sys.executable)

VS Code importing the multiarray numpy extension module failed

import numpy
is not working. This started because I couldn't get PyQt5 to work on my home computer. In the Spyder IDE, I can import modules and get everything working fine, but in VS Code, I can't import basic modules. I'm on Windows 10 with Python 3.7. I've Googled a lot and have tried these:
Uninstall Anaconda and VS Code, and reinstall both
In VS Code, press Ctrl+Shift+P, Select Interpreter, and select Python 3.7.1 64-bit ('base':conda), ~\Anaconda3\python.exe
I saw on another similar question that python3.dll may be missing from one of my Anaconda directories, but it is indeed there.
Add environment variable to PATH by going to System Properties > Advanced tab > Environment Variables... > under System Path, Edit, New > C:\Users\myname\Anaconda3\Scripts
Once I did #4 above, the new error message in VS Code when importing numpy is DLL load failed: The specified module could not be found. And in the terminal, I see: The term 'conda' is not recognized as the name of the cmdlet, ...
One thing I notice is in a Python prompt (not Anaconda) I type:
import sys
print(sys.version)
The output is 3.7.2, while in VS Code, the Select Interpreter (see above #2) says Python 3.7.1. Not sure if this is important.
Any help? Everything works on my work computer fine, but it's just my home computer that is being difficult.
What ended up working for me is downgrading my Python installation from 3.7.1 to 3.6.4 with:
conda install python=3.6.4
Hope this helps someone out there.
On another question for the same problem, there was a suggestion that worked for me.
Put this on the variable path.
C:\Users\<Your user name>\Anaconda3\Library\bin
credit to user1024.

IPython notebook kernel dies on import

I am running IPython Notebook on Enthought's Canopy 64 bit distribution, Ubuntu 14.04.
I've tried install libtiff, but when I import it in IPython Notebook, the kernel always dies at the import statement. What could possibly be causing this? Canopy is my default Python distribution, my paths all seem like they're set up appropriately, although I'm convinced that something in my Python setup is borked.
Any advice is appreciated.
EDIT: I'll be more specific. Output of sys.path:
['',
'/home/joe/Enthought/Canopy_64bit/User/src/svn',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python27.zip',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/plat-linux2',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/lib-tk',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/lib-old',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/lib-dynload',
'/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages',
'/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/PIL',
'/home/joe/opencv-2.4.9',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/site-packages',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/site-packages/IPython/extensions']
As for how to install Python packages, I assume I go to ~/Enthought/Canopy_64bit/User/lib/python2.7/site-packages and run pip, setup.py, or a shell script, per the specific package's instructions. Is that correct? The article that I linked has the following line: "To install a package which is not available in the Canopy / EPD repository, follow standard Python installation procedures from the OS command line.", which seems to imply that I install per package instructions.
In .bashrc, I have the following:
VIRTUAL_ENV_DISABLE_PROMPT=1 source /home/joe/Enthought/Canopy_64bit/User/bin/activate
export PYTHONHOME=/home/joe/Enthought/Canopy_64bit/User/bin
export PATH=/home/joe/Enthought/Canopy_64bit/User/bin
export PYTHONPATH=/home/joe/Enthought/Canopy_64bit/User/bin
From what I understand of the linked articles, this means I'm setting Canopy User as my default Python distribution. I'm sure I'm doing something a bit over my head here, but I can't understand what else I need to do to fix this issue.
Worse yet, now I'm getting an "ImportError: No module named site" with these .bashrc settings, when trying to start IPython notebook or python from the command line. I can run only from the Canopy GUI.
Closing this. I made it harder than necessary.
It turns out, the PYTHONHOME and PYTHONPATH .bashrc variables were causing some conflicts. Commenting them out seems to have resolved the issue.
Installing outside packages does, indeed, happen from the home (~) directory.

Import error when using a python script that do not occur in ipython

All my install for python were working pretty well since soon. Now, I have a weird issue that generates import errors for some of my Python scripts and when using Ipython those import performs as expected.
This issue does not depend on the working dir (tested this several times with the same result). And I didn't change anything in my .bashrc regarding PYTHONPATHs.
So this might be a noob question, but is there an option in Ipython to display everything Ipython is doing when I run a command, so that I can track which is the package Ipython succesfully imported?
The packages I have trouble with are actually yaml, matplotlib cloud Image. Is it possible that an update from 2.6 to 2.7 is responsible for that? (I work on OSX Lion and most of the packages are installed via macports and updated using the upgrade outdated command).
As I think I can probably fix this myself with the command I asked for, don't bother seeking further for package compatibility or anything if you got the Ipython command that might suits me.
The difference of imports between python and ipython resulted from a cross defined python reference library (when installing most of the python libraries with macports and some without any known ports with other package managers).
Reinstalling the whole python libraries using the process described in http://astrofrog.github.io/macports-python/
corrects the issue and it is preferable to install manually the libraries that don't have any known ports (for instance with a setup build/install process).

"Undefined variable from import" when importing numpy in eclipse pydev

I get "Undefined variable from import" error in Eclipse 3.7.2 PyDev 2.7.1 on Linux Mint Maya (Cinnamon) whenever I import a module from numpy. The problem only arises when importing numpy; other modules work just fine.
Info: numpy is compiled against the Intel MKL libraries. Python 2.7.3 [GCC 4.6.3]
example:
import numpy as np
a = np.array([1, 2])
Error message in PyDev editor:
"Undefined variable from import: array"
I get similar errors for other numpy submodules.
The code runs properly either within Eclipse or in a terminal. The problem is only present in the Eclipse-PyDev editor.
The LD_LIBRARY_PATH has to contain paths to the MKL libraries. Even if LD_LIBRARY_PATH is set properly, it has to be explicitly specifed in Eclipse under Window > Preferences > Interpreter - Python, under the "Environment" tab on the right hand side. Add a new variable called "LD_LIBRARY_PATH" and paste the content of $LD_LIBRARY_PATH.
Once it is done, errors will only disappear from your code if a line is added to the code which uses a numpy object so that imports are checked again.
I managed to fix it by updating the Phyton interpreter in Eclipse. Just click on Apply button after successfully installed Numpy module.
Are MKL libraries and numpy the same thing? #user1898039's answer didn't make sense to me (I'm not sure what path I should use for that property.
I found another way to fix this issue - I checked the python command line to see if numpy was installed there by calling:
>>> import from numpy *
It was not. So, despite the fact that numpy was showing up in PyDev under the "Forced Builtins" tab in the Python Interpreter properties, it wasn't available to python from the command line and I imagine this caused the issue inside PyDev.
So, I fixed the problem by going to the numpy site and installing the newest version for windows. Technically I went to some other site that had a AMD64 version of the installer for windows, buy you know, same same. After that I tried to get the PYTHONPATH variable to recalculate all the libraries (this may have been unnecessary), but errors were still showing in the file on all the calls to array(). I did an autocomplete on the numpy package to get the list of functions, selected array() from that list, and all of the sudden all the errors cleared and everything is fine now.
I was able to resolve this by adding the following path to PYTHONPATH (Pydev => Python Interpreters => select an Interpreter => Libraries):
/usr/local/anaconda/lib/python2.7/lib/lib-dynload
installed packages (among others):
conda==3.10.1
numpy==1.9.2
scipy==0.15.1
I occasionally see these errors for pandas objects, after re-starting Eclipse, even though I of course have 'import pandas as pd' at the top of my file.
I've discovered a simple workaround: I simply delete the import statement, save the file, paste it back in and re-save. The errors go away!
I'm on this version of Eclipse:
Eclipse for PHP Developers
Version: Mars.2 Release (4.5.2)
Build id: 20160218-0600