Anaconda/Python/VSCode: vscode editor doesn't recognize installed packages - python

I'm trying to use VS Code for python in an Anaconda environment. I have (after some googling and travail) gotten it using my custom environment. However, pylint and the editor don't recognize the installed netifaces in the environment.
The environment (billh) is being loaded:
The errors from python are shown here:
Oddly, importing from ipython running in the built-in terminal does work:
This was newly installed today, via Anaconda. Here's the version info

It isn't that the extension can't find the netifaces package, it's that Pylint can't. Make sure that the Pylint you are having the extension run for you is installed into the same conda environment that you are running from (e.g. make sure you didn't set python.linting.pylintPath to something outside of your conda environment). Also make sure that ipython is from the same environment as well (e.g. you are using a conda environment and launched the terminal with the Python: Create Terminal command).

Related

How can you connect a jupyter notebook to a pipenv virtual environment using vscode?

I'm working on a project and was trying to set up a jupyter notebook to have access to the virtual environment. I set up the virtual environment just using pipenv install pandas, and that created the pipfile and the pip lock file. I then imported pandas in the jupyter notebook and tried printing out the version number, and got a ModuleNotFoundError: No module named 'pandas' error, meaning that the notebook is not connected to the virtual environment. I'm editing jupyter notebooks in vscode, and was wondering how I could connect the notebook to the pipenv environment?
Regarding using a virtual environment in Jyputer in VS Code and checking the python modules in this environment, you could refer to the following:
Please make sure that the upper right corner of Jupyter is using the python environment you need.
Please use "pip show pandas" to check whether the module "pandas" has been installed in the current environment.
In addition, since the python environment used by Jupyter in VS Code can be different from the environment used by VS Code, please check the selection of the relevant environment, and check the python environment currently used when installing the module on the VS Code terminal. (python --version or pip --version)
Reference: Python environments and Jupyter in VS Code.

NEST simulator:python says "ModuleNotFoundError: No module named 'nest'"

My python version in mac is 3.8 but I need 3.7 so I create environment python 3.7, and install the nest with conda. But when I import nest, there is still the error:ModuleNotFoundError: No module named 'nest'.
I checked the python3.7/site-packages, there is the nest:
It sounds like you're running the wrong Python binary (native version instead of 3.7). If you want to use a specific Python version, you could add it's install location to your $PATH before the system version.
You could use a tool like pyenv to help you manage your selected Python version (see this article).
When using an IDE (xcode, pycharm, etc.), it may not be aware of your conda environment and use the system python (which doesn't know about the conda installed NEST). You could check the corresponding runtime environment settings in the IDE to correctly reflect your py37 conda environment.
However, when you run python --version in your environment on the shell, it should correctly give 3.7 and the "which python" should point to your conda installed Python version in the py37 environment. If this is the case then python -c "import nest" should work.
(this answer could also help with the setup)

Yahoo finance in Spyder (Anaconda)

I successfully installed Yahoo finance in Anaconda
When I type
pip list
in the Anaconda Prompt, it shows that yahoo finance is there.
But when I try to import it on Spyder, I get the error:
"No module named 'yfinance"
Basically your error message it because Spyder isn't configured to work with conda's environment.
Check this link here and the possibles solutions from it:
Installing packages into the same environment as Spyder
Spyder is a Python package just like any other you may be used to, and so you can import any package within its Console or Editor as you could from a regular Python or IPython terminal launched in Spyder's environment:
If Spyder is installed with Anaconda (as we recommend) and launched
via a shortcut, from Anaconda Navigator or from Anaconda Prompt
without modifying anything, this will be the default base Anaconda
environment.
If Spyder is installed via pip (experts only) and not into a virtualenv/venv, this will usually be whatever Python installation pip itself belongs to.
If you use a system package manager (apt-get, dnf, emerge, etc) to install Spyder, this will typically be your system Python and its library of packages.
If you installed Spyder into a specific environment (conda-env or venv), or it came with a pre-configured one (like those for Keras or TensorFlow) and launched it from there, it will only have access to packages from that environment.
Therefore, if you'd like to use a package with your existing Spyder install (e.g. import'ing it into your scripts, packages or a Spyder IPython console), the simplest way to do so is to install the package into the same environment in which you installed Spyder, typically by the same means you installed Spyder (conda, pip, package manager, etc). However, if you're installing packages with pip, conda-forge, Github, or custom channels, working on multiple major projects at once, using prebuilt environments, or otherwise have more sophisticated needs, you'll likely want to use one or more separate environments for your packages. If so, the next section explains how.

Pycharm doesnt reslove package dependencies

I installed a pycharm application and did configure interpreter. After i installed spark-nlp package via pip inside pycharm, and tried to run programm, it showed that it missing dependecy in form of pyspark package. When I installed pyspark it complained about bunch of packages that are being missing. Shouldn't venv resolve all requirements automatically?
For this to work "pip" should be associated with the Python interpreter you have specified in Pycharm.
Can you check if the interpreter specified in Pycharm and "pip" on the terminal are pointing to same virtualenv which was created?
I believe "pip" on pycharm-terminal is different and not pointing to virtualenv used by Pyharm.

How to install Matplotlib for anaconda 1.9.1 and Python 3.3.4?

I am configuring Anaconda 1.9.1 together with Python 3.3.4 and I am unable to setup Matplotlib for anaconda environment when I try to add package using Pycharm. I also tried to install from Matplotlib.exe file which I downloaded from its website. I can not change the installation directory in that case. I would like to know that is there a way to tackle this issue.
If you're using anaconda, your default environment is Python 2.7. You need to create a new environment and install matplotlib in there.
In a command prompt, do the following (saying yes to the questions):
conda create --name mpl33 python=3.3 matplotlib ipython-notebook
activate mpl33
ipython notebook
You should be able to import matplotlib when the notebook server comes up.
The first command simultaneously creates the environment and install
the listed packages.
The second command activates the new environment by prepending its location to the system path
The third command just starts the ipython notebook so that you can test out everything
I don't know how pycharm works, but my guess is that you'll have to tell it to look for the right python that you want to use. In this case it'll be something like: C:/Users//anaconda/envs/mpl33. In any case, the command prompt should display the path when you activate the environment.
Once you've activated your environment, you can install more packages like this:
conda install pandas=0.12
conda install pyodbc statsmodels
You can specific version numbers of packages like the first command or simply accept the latest available version (default)
Assuming you've already installed a 3.x python env in anaconda, this one line should do the trick:
conda install matplotlib -n name
where name is the name you previously gave to your python 3 anaconda env. If you're not sure of the name you gave it, it will be the name of a subdir in the Anaconda\envs directory.
Background: I recently went through the same trouble with matplotlib not getting installed by default by anaconda when I added a full python 3 env, even though it's meant to. The above line solved it for me; it gave me the following warnings so it seems likely that the two different available versions caused it to initially install neither. However it allowed me to choose the one I wanted, and then everything worked great.
Warning: 2 possible package resolutions:
[u'dateutil-2.1-py33_2.tar.bz2', u'matplotlib-1.3.1-np18py33_1.tar.bz2', u'numpy-1.8.0-py33_0.tar.bz2', u'pyparsing-2.0.1-py33_0.tar.bz2', u'pyside-1.2.1-py33_0.tar.bz2', u'python-3.3.5-0.tar.bz2', u'pytz-2013b-py33_0.tar.bz2', u'six-1.6.1-py33_0.tar.bz2']
[u'dateutil-2.1-py33_2.tar.bz2', u'matplotlib-1.3.1-np17py33_1.tar.bz2', u'numpy-1.7.1-py33_3.tar.bz2', u'pyparsing-1.5.6-py33_0.tar.bz2', u'pyside-1.2.1-py33_0.tar.bz2', u'python-3.3.5-0.tar.bz2', u'pytz-2013b-py33_0.tar.bz2', u'six-1.6.1-py33_0.tar.bz2'
]
conda install -c conda-forge matplotlib

Categories