Installing python packages from cmd in windows 10 - python

I recently downloaded anaconda and added it to the environment variables following the question below:
anaconda - path environment variable in windows.
I added it as
C:\Users\My_User\Anaconda3
The thing is, I've been trying to install some packages using either pip or conda without luck.
For instance:
pip install seaborn
Return the following
Error output
Does somebody know how can I enable package installation either through pip or conda?
I'm very new to executing commands through cmd and couldn't figure out a better way to type my question, sorry about that

Step 1:
Open Anaconda Navigator
navigator
Step 2:
Go to Environments and select All packages, to view the list of all packages installed.
environment packages
Step 3:
Look for seaborn in the Search bar
search bar
Install it and see if that works.
If it doesn't then try creating a new environment and installing the seaborn package there. create new environment

Try
python -m pip install seaborn

You're getting this error because you're running pip from inside of the Python interpreter when you should be running it from the command line. To exit the Python interpreter, press ctrl+d. Then, make sure you have pip installed and in your PATH and you can try again.

Related

I installed package, but python said No moudel <name-packages> any packages I try to install it

I try using pip and pip3 and python -m pip and all ways to install. The terminal says the packages already installed after the first try to install, but when I try to import the package I had error no moudel name.
I feel the peoblem coming form here
But I am not sure
And when I go to packages in pycharm I saw the packages not installed
I appreciate your help
I'm assuming you're using windows.
It looks like you install the package directly in your system and PyCharm are using a virtual environment to run your code.
Try to activate this virtual environment before run your code:
source venv\Scripts\activate
If you see "(venv)" at the begging of your terminal prompt the virtual environment are activated.
Run pip list to check what packages are installed in there and probably you have to install your package another time, this time in your activated virtual environment. The official documentation will help to understand how and why use virtual environments.
After that you can try to run your code directly from the terminal:
python your_file.py
Install the packages from PyCharm itself, not the terminal as I think pycharm is running a virtual environment.
Maybe you can follow https://www.jetbrains.com/help/pycharm/installing-uninstalling-and-upgrading-packages.html#packages-tool-window

How to install python library to specific environment (without conda)

Update update: json_lines is not supported by python versions < 3 - my issue had pretty much nothing to do with environments. I am now using 3.9.1 and all is gucci.
Update: After using which python in my jupyter notebook and in my Terminal, I see that they are both using the same environment. As such I am still at a loss as to why my notebook cannot find json_lines.
I have two python environments on my computer, a default one and one I have for running my jupyter notebook on. I am trying to install the library, json_lines to the latter environment. I am not used the Anaconda environment manager.
On my Mac's Terminal I used the general pip install command pip install json-lines, but when I try to execute the following line of Python import json_lines in my notebook, I still receive the following error ImportError: No module named json_lines.
As I suspect I am not installing to the correct environment, I tried installing the library from inside my notebook with the following, import sys; !{sys.executable} -m pip install jsonlines.
However, this has not changed my dilemma.
Is there some way I can specify from my Terminal which environment to install to? or is it likely I am encountering a different issue to what I suspect?
The package for json_lines in pip in json-lines. Hence you could install it as:
$ pip install json-lines
It may be appropriate to use an isolated python environment for your particular project if you want to use particular conda libraries but without the whole package. In this instance, you would be able to use virtualenv. This will allow you to create an isolated python environment.
$ pip3 install virtualenv
You can call virtualenv to create a virtual python environment with the working name e.g. myvenv.
$ virtualenv myvenv
From here, you can set your terminal to use this python version. If you are on *nix:
$ which python
/usr/bin/python
$ source myvenv/bin/activate
(myvenv)$ which python
/.../myvenv/bin/python
This article can help you out.
https://janakiev.com/blog/jupyter-virtual-envs/
You need to create a virtualenv which will be used by your notebooks.

How can I point my Spyder IDE to the path where all packages are installed?

I had a massive crash today and lost a lot of work. I couldn't start Spyder after many attempts; even tried 'spyder --reset'. Nothing worked. I decided to download a new version of Anaconda and start over. Now, I'm trying to figure out why I can't run packages.
If I run this: import pyodbc
I get this: ModuleNotFoundError: No module named 'pyodbc'
So, I go to the command prompt to pip install pyodbc...and apparently it's already installed...
When I navigate to that path, I can see the package
...but Spyder is still telling me it's not installed. What's an easy fix for this?
i had similar crash problems on Windows 10, what I learned is that I had several non-conda versions of python on my PC, and I used 'pip install' in my environments so it messed up with conda packages and it stop working.
What I did is that I uninstalled anaconda and non-conda python, cleaned up registry from python mentions, installed fresh new miniconda, and 'conda install spyder' in the new env, conda have created new folder
C:\Users\~~~\.spyder-py3\
Inside of it I found "spyder.ini" file, where incorrect variable was set:
"spyder_pythonpath = "
I changed it from
['C:\Users\~~~\anaconda3\pkgs',
'C:\Users\~~~\anaconda3\envs']
to
['C:\Users\~~~\miniconda3\pkgs',
'C:\Users\~~~\miniconda3\envs']
Please Upvote it take so much time
First open Spyder and click Tools --> Open command prompt.
You should see the Command Window appear in the bottom right of your screen.
Here we install the Python package seaborn as an example.
# In the command line, type pip install seaborn
C:\Users\your_username\Documents\Python Scripts>pip install seaborn
This will install seaborn on your machine.
Note:
To upgrade the pip version on Windows, type python -m pip install --upgrade pip on the command line.
On Windows, all of your Python packages can be found in the directory of C:\Anaconda2\Lib\site-packages if you use the default path when you install Anaconda.
To upgrade the pip version on OS X, type pip install --upgrade pip on the command line.

ModuleNotFoundError: No module named 'pynput'

I am writing some basic code in visual studio code and I am trying to use pynput, but when I import the module despite the fact that I installed it using pip it gives me this error:
ModuleNotFoundError: No module named 'pynput'
I have tried to install it using pip3, but it doesn't work
I have also tried to install it using the path interpreter, but it still doesn't work
This is the code:
from pynput.mouse import Button, Controller
mouse = Controller()
# Read pointer position
print('The current pointer position is {0}'.format(
mouse.position))
Strange thing is that this code works in sublime text 3,
but doesn't work in neither visual studio code nor cmd.
Thank you in advance.
Your package associations may be incorrect.
First, see where your IDE is running python. it should be something like C:\programData\Python
Reinstalling the python interpreter may fix this. Or try upgrading the pip, which uninstalls the old one, and pulls down the new one from the cloud. Open a CMD windows, and type the following command:
python -m pip install --upgrade pip --user
This will give you a fresh pip installation. Then try "pip install pynput"
If this does not solve the issue, uninstall your current interpreter, then go to python.org, and download and install the latest interpreter. Upgrade the pip.
if you are trying to run it from within the IDE, check the paths in witch it calls the python interpreter.
if it's pointing to any conda installation try conda install pynput instead
Most IDEs create an "interpreter" for your project, which in python-speak means that the IDE set up a "virtual environment" for you. Virtual environments are great for managing dependencies across different projects. For example if you need one version of pynput for one project and a later version for another project, you can do this with two separate virtual environments, whereas if you installed pynput on your system, upgrading pynput would break your first project. More info on virtual environments
When you open command line and run pip install, this installs the package onto your system interpreter. You'll instead need to 'activate' your virtual environment and run the pip install there. You can find the path to your virtual environment by opening your interpreter settings in your IDE. Then follow these instructions to activate your virtual environment and run the pip install on your project interpreter.
Try this
pip uninstall pynput
pip install pynput
or
install pynput using conda
conda install pynput

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