I've been looking everywhere and cannot find a robust explanation.
I'm brand new to Python, coming from R. I had no issues installing packages there but I'm finding it to be rather confusing in Python.
So, I'm using Anaconda and I want to install this package into Python. It mentions using the conda install -c https://conda.anaconda.org/amueller wordcloud command but I have no idea where I'm supposed to run it.
Any advice would be much appreciated.
If you can't find a package with a simple conda search from the command line, run a search on the Anaconda website.
In your case, you'll find that the contributor amueller has his own channel and the package wordcloud is available.
Just run conda install -c amueller wordcloud=1.2.1 to install it.
You might want to create a separate environment using conda create first.
Run it from command line. You can directly install using pip as mentioned in the link. Don't forget to install the pre-requisite packages.
pip install wordcloud
If you are using windows, make sure your environmental path is set so that you can use the pip command directly from windows command prompt. Usually the environmental variable is updated when you install Anaconda distribution.
Conda is just another command which you can use to install packages. Procedure is exactly the same.
You may install packages from interface
Interface
Related
I have been trying to use a Conda Environment and I am working with Python 3.10.2. I want to install Pandas and SciPy through Miniconda. I downloaded it but when I tried running conda install pandas on the command prompt it says that "Conda is not recognised as an internal or an external command, a program or a batch file'. What could have gone wrong?
Can you also suggest an alternate way to download Pandas?
Conda probably wasn't added as a path variable. Locate the conda.exe add it to the path.
Can you also suggest an alternate way to download Pandas?
You could use pip:
pip install pandas
I am doing this project where i need to install a package called Twint.
I want to install this package and use it's commands in my VS Code.
What happends when i for example type this in my Windows CMD?
pip3 install --user --upgrade git+https://github.com/twintproject/twint.git#origin/master#egg=twint
Because i can't type this in my VS code terminal, where i usually install packages with pip.
It will return an error that says ERROR: Cannot find command 'git' - do you have 'git' installed and in your PATH?''
Now if i run this in my Windows Command it seems that i can't directly import the package in VS code?
Can anyone help me out with this confusion, where does the files get stored and how do i create good habbits around installing packages?
Hope someone understands what im struggeling with here.
Best
It is often the case that computers have more than one version of python installed and that editors like VS code use a different version than pip uses on the command line. pip installs packages where the version of python it is linked to expects them to be, but VScode doesn't know to look there.
It sounds like you have git installed where pip installs things, so you can upgrade from the command line without issue, but there's no installation of git where VScode is looking, so there's nothing to upgrade.
You either need to find where pip installs things and add it to the $PATH VScode uses, or try running a variation of python -m pip install --user git (specifying a specific url, or other things, as needed) from within VScode, which will ensure the package gets installed in a place that VScode looks for packages.
Download and Install git in your windows from here:
https://git-scm.com/download/win
Then add its installation bin path to your windows's environment path. Then you will find the git command at the command prompt globally.
This may solve you problem.
Please provide a solution regarding this I tried the pipwin approach its not working and if anyone know how to create a virtual environment of 3.7 for u sing pyaudio can share idea would be a great
You can create virtual environment using(If you have anaconda installed)
conda create -n myenv python=3.7
then you can use
pipwin install pyaudio
You can also use this link to download .whl file according to the python version it supports.
Go to the following directory and run this command on command prompt (Windows here) .
C:\Users\jay_p\AppData\Local\Programs\Python\Python39\Scripts>pip install PyAudio-0.2.11-cp39-cp39m-win64.whl
(This may be different for you.)
I want to import sklearn but there is no module apparently:
ModuleNotFoundError: No module named 'sklearn'
I am using Anaconda and Python 3.6.1; I have checked everywhere but still can't find answers.
When I use the command:
conda install scikit-learn should this not just work?
Where does anaconda install the package?
I was checking the frameworks in my python library and there was nothing about sklearn only numpy and scipy.
Please help, I am new to using python packages especially via anaconda.
You can just use pip for installing packages, even when you are using anaconda:
pip install -U scikit-learn scipy matplotlib
This should work for installing the package.
And for Python 3.x just use pip3:
pip3 install -U scikit-learn scipy matplotlib
Will leave below two options that may help one solve the problem:
Using conda
Using pip
One might want to consider the notes at the end, specially before resorting to the 2nd option.
Option 1
If one wants to install it in the root and one follows the requirements - (Python (>= 2.7 or >= 3.4), NumPy (>= 1.8.2), SciPy (>= 0.13.3).) - the following should solve the problem
conda install scikit-learn
Alternatively, as mentioned here, one can specify the channel as follows
conda install -c anaconda scikit-learn
Let's say that one is working in the environment with the name ML.
Then the following should solve one's problem:
conda install -n ML scikit-learn
# or
conda install -n ML -c anaconda scikit-learn
Option 2
If the above doesn't work, on Anaconda Prompt one can also use pip (here's how to pip install scikit-learn), so the following may help
pip install scikit-learn
However, consider the last note below before proceeding.
Notes:
When using Anaconda, one needs to be aware of the environment that one is working.
Then, in Anaconda Prompt, one needs to run the following
conda $command -n $ENVIRONMENT_NAME $IDE/package/module
$command - Command that one intends to use (consult documentation for general commands)
$ENVIRONMENT NAME - The name of one's environment (if one is working in the root,
conda $command $IDE/package/module is enough)
$IDE/package/module - The name of the IDE or package or module
If one needs to install/update packages, the logic is the same as mentioned in the introduction. If you need more information on Anaconda Packages, check the documentation.
What is the flag -c.
pip doesn't manage dependencies the same way conda does and can, potentially, damage one's installation.
If you are using Ubuntu 18.04 or higher with python3.xxx then try this command
$ sudo apt install python3-sklearn
then try your command. hope it will work
I did the following:
import sys
!{sys.executable} -m pip install sklearn
I've tried a lot of things but finally, including uninstall with the automated tools. So, I've uninstalled manually scikit-learn.
sudo rm -R /home/ubuntu/.local/lib/python3.6/site-packages/sklearn
sudo rm -R /home/ubuntu/.local/lib/python3.6/site-packages/scikit_learn-0.20.0-py3.6.egg-info
And re-install using pip
sudo pip3.6 install -U scikit-learn
Hope that can help someone else!
This happened to me, I tried all the possible solutions with no luck!
Finaly I realized that the problem was with Jupyter notebook environment, not with sklearn!
I solved the problem by re-installing Jupyter at the same environment as sklearn
the command is: conda install -c anaconda ipython. Done...
The other name of sklearn in anaconda is scikit-learn. simply open your anaconda navigator, go to the environments, select your environment, for example tensorflow or whatever you want to work with, search for scikit_learn in the list of uninstalled packages, apply it and then you can import sklearn in your jupyter.
SOLVED:
The above did not help. Then I simply installed sklearn from within Jypyter-lab, even though sklearn 0.0 shows in 'pip list':
!pip install sklearn
import sklearn
What I learned later is that pip installs, in my case, packages in a different folder than Jupyter. This can be seen by executing:
import sys
print(sys.path)
Once from within Jupyter_lab notebook, and once from the command line using 'py notebook.py'.
In my case Jupyter list of paths where subfolders of 'anaconda' whereas Python list where subfolders of c:\users[username]...
On Windows, I had python 3+ version. pip version - 22.3.1
I had installed:
pip install sklearn
But, it seems it is deprecated with scikit-learn.
So, I did:
pip install scikit-learn
And, it worked!!!
Cause
Conda and pip install scikit-learn under ~/anaconda3/envs/$ENV/lib/python3.7/site-packages, however Jupyter notebook looks for the package under ~/anaconda3/lib/python3.7/site-packages.
Therefore, even when the environment is specified to conda, it does not work.
conda install -n $ENV scikit-learn # Does not work
Solution
pip 3 install the package under ~/anaconda3/lib/python3.7/site-packages.
Verify
After pip3, in a Jupyter notebook.
import sklearn
sklearn.__file__
~/anaconda3/lib/python3.7/site-packages/sklearn/init.py'
I had the same problem.
The issue is when we work on multiple anaconda environments, not all packages are installed in all environments.
you can check your conda environment by writing the following code in anaconda prompt:
conda env list
then you can check the packages installed in each environment :
conda list -n NAME_OF_THE_ENVIRONMENT
for me, the environment that I was working with , was missing sklearn, although the package was installed in the other environments.
therefore, I just simply installed sklearn package in that particular environment
conda install -n NAME_OF_THE_ENVIRONMENT scikit-learn
and the issue was resolved
install these ==>> pip install -U scikit-learn scipy matplotlib
if still getting the same error then ,
make sure that your imoprted statment should be correct. i made the mistike while writing ensemble so ,(check spelling)
its
should be >>> from sklearn.ensemble import RandomForestClassifier
I had the same issue as the author, and ran into the issue with and without Anaconda and regardless of Python version. Everyone's environment is different, but after resolving it for myself I think that in some cases it may be due to having multiple version of Python installed. Each installed Python version has its own \Lib\site-packages\ folder which can contain a unique set of modules for that Python version, and where the IDE looks into folder path that doesn't have scikit-learn in it.
One way to try solve the issue: you might clear your system of all other Python versions and their cached/temp files/system variables, and then only have one version of Python installed anywhere. Then install the dependencies Numpy and Scipy, and finally Scikit-learn.
More detailed steps:
Uninstall all Python versions and their launchers (e.g. from Control Panel in Windows) except the one version you want to keep. Delete any old Python version folders in the Python directory --uninstalling doesn't remove all files.
Remove other Python versions from your OS' Environment Variables (both under the system and user variables sections)
Clear temporary files. For example, for Windows, delete all AppData Temp cache files (in C:\Users\YourUserName\AppData\Local\Temp). In addition, you could also do a Windows disk cleanup for other temporary files, and then reboot.
If your IDE supports it, create a new virtual environment in Settings, then set your only installed Python version as the interpreter.
In your IDE, install the dependencies Scipy and Numpy from the module list first, then install Scikit-Learn.
As some others have suggested, the key is making sure your environment is set up correctly where everything points to the correct library folder on your computer where the Sklearn package is located. There are a few ways this can be resolved. My approach was more drastic, but it turns out that I had a very messy Python setup on my system so I had to start fresh.
Using Anaconda-navigator UI environment
When running Anaconda-navigator:
Choose the 'Environments' tab on the left and create a new environment (e.g. ML - see Gonçalo Peres answer above, I made one called 'CourseraML').
Set Python version 3.7 (for Coursera course Applied Machine Learning in Python). Also include R.
Then find modules to install using the 'not installed' drop-down menu item. Search for each module needed in the search bar and select. sklearn is part of scikit-learn. Select it and install (it should find all relevant dependencies). Modules needed for Applied ML course: seaborn, numpy, scikit-learn, pandas, matplotlib
You'll need to restart Jupyter Notebook and reopen your file.
Command line version of above:
conda install -n CourseraML seaborn scikit-learn pandas numpy matplotlib graphviz
Causes
-your jupyter notebook might be importing the sklearn and other libraries from the
another the location(path) than the libraries from conda or pip.
MY Problem
In my case, My jupyter notebook was importing the libraries for snap manager. Since, I install jupyter using the snap instead of other ways.
You can check where other libraries are being imported in jupyter using code:
import cv2 as cv
print(cv.__file__)
Solution
So , I uninstall jupyter notebook and then install notebook using conda.
sudo snap remove jupyter
conda install -c conda-forge notebook
I use an out-of-the-box Anaconda installation to work with Python. Now I have read that it is possible to also "include" the R world within this installation and to use the IR kernel within the Jupyter/Ipython notebook.
I found the command to install a number of famous R packages:
conda install -c r r-essentials
My beginner's question:
How do I install R packages that are not included in the R-essential package? For example R packages that are available on CRAN. "pip" works only for PyPI Python packages, doesn't it?
Now I have found the documentation:
This is the documentation that explains how to generate R packages that are only available in the CRAN repository:
https://www.continuum.io/content/conda-data-science
Go to the section "Building a conda R package".
(Hint: As long as the R package is available under anaconda.org use this resource. See here: https://www.continuum.io/blog/developer/jupyter-and-conda-r)
alistaire's answer is another possibility to add R packages:
If you install packages from inside of R via the regular install.packages (from CRAN mirrors), or devtools::install_github (from GitHub), they work fine. #alistaire
How to do this:
Open your (independent) R installation, then run the following command:
install.packages("png", "/home/user/anaconda3/lib/R/library")
to add new package to the correct R library used by Jupyter, otherwise the package will be installed in /home/user/R/i686-pc-linux-gnu-library/3.2/png/libs mentioned in .libPaths() .
To install other R Packages on Jupyter beyond R-essentials
install.packages('readr', repos='http://cran.us.r-project.org')
One issue is that the specific repository is the US.R-Project (as below). I tried others and it did not work.
N.B. Replace readr with any desired package name to install.
Here's a conda-centric answer. It builds on Frank's answer and the continuum website: https://www.continuum.io/content/conda-data-science with a bit more detail.
Some packages not available in r-essentials are still available on conda channels, in that case, it's simple:
conda config --add channels r
conda install r-readxl
If you need to build a package and install using conda:
conda skeleton cran r-xgboost
conda build r-xgboost
conda install --use-local r-xgboost
that last line is absent in the continuum website because they assume it gets published to anaconda repository first. Without it, nothing will be put in the envs/ directory and the package won't be accessible to commandline R or Jupyter.
On a mac, I found it important to install the Clang compiler for package builds:
conda install clangxx_oxs-64
I found an easy workaround. I suppose that you have an RStudio IDE for you R. It is weird to use RStudio for that, but I tried straight from R in my terminal and it didn't work. So, in RStudio console, just do the usual adding the path to your anaconda directory (in OSX,'/Users/yourusernamehere/anaconda/lib/R/library')
So, for example,
install.packages('package','/Users/yourusernamehere/anaconda/lib/R/library')
I feel ashamed to post such a non-fancy answer, but that is the only one that worked for me.
Adding it here so other beginners already working with Jupyter notebooks with Python and interested in using it with R: additional packages available for Anaconda can be installed via terminal using the same command used to instal the essential packages.
Install r-essentials
conda install -c r r-essentials
Install microbenchmark (infrastructure to accurately measure and compare the execution time of R expressions)
conda install -c r r-microbenchmark
To install a CRAN package from the command line:
R --slave -e "install.packages('missing-package', repos='http://cran.us.r-project.org')"
I had a problem when trying to install package from github using install_github("user/package") in conda with r-essentials. Errors were multiple and not descriptive.
Was able to resolve a problem using these steps:
download and unzip the package locally
activate correct conda environment (if required)
run R from command line
library(devtools)
install('/path/to/unzipped-package')
Command failed due to missing dependancies, but now I know what's missing!
run install.packages('missing-package', repos='http://cran.us.r-project.org') for all dependancies
run install('/path/to/unzipped-package') again. Now it should work!
Use Conda Forge
Five years out from the original question, I'd assert that a more contemporary solution would simply be: use Conda Forge. The Conda Forge channel not only provides broader coverage of CRAN, but also has a simple procedure and great turnaround time (typically under 24 hours) for adding a missing CRAN package to the channel.
Start from Conda Forge
I'd recommend using Conda Forge for the full stack, and use a dedicated environment for each R version you require.
conda create -n r41 -c conda-forge r-base=4.1 r-irkernel ...
where ... is whatever additional packages you require (like r-tidyverse). The r-irkernel package is optional, but included here because OP mentions using R in Jupyter.
If your environment with Jupyter (which should be in a separate environment) also has nb_conda_kernels installed, then this environment will automatically be discovered by Jupyter.
Install from Conda Forge
Generally, all R packages on CRAN have a r- prefix to the package name on Conda Forge. So, if your package of interest is pkgname, first try
conda install -n r41 -c conda-forge r-pkgname
If the package is not available, then proceed to either add it or request it.
Submit a CRAN package with Conda R Skeleton Helper
There is a helpful script collection, called conda_r_skeleton_helper for creating new Conda Forge recipes for CRAN packages. There are clear directions in the README.
In broad strokes, one will
clone the conda_r_skeleton_helper repository
edit the packages.txt file to include r-pkgname
run the script to generate the recipe
fork and clone the conda-forge/staged-recipes
copy the new recipe folder to the stage-recipes/recipes folder
commit changes, push to the fork, then submit a Pull Request back to Conda Forge
This takes maybe ~15 mins of work. Once submitted, most packages take under 24 hours to get accepted, feedstocked, and deployed to the Conda Forge channel. Once the feedstock is up and running, the Conda Forge infrastructure uses a bot to auto-detect version updates, generate new pull requests, and even auto-merge Pull Requests that successfully build. That is, maintainers have a very minimal workload, and if there are issues, a team is available to help out.
File a Package Request
For users uncomfortable with creating and maintaining a Conda Forge build, packages can be requested on Conda Forge's staged-recipes repository by filing a new Issue. There is a template for Package Request, that includes some information fields to be filled in.
Install rpy2 with conda and add following line in your Jupyter notebook.
%load_ext rpy2.ipython
In next chunks, you can simply run any r code by specifying %R
Below is my favorite method to install and/or load r package
%R if (!require("pacman")) install.packages("pacman")
%R pacman::p_load(dplyr, data.table, package3, package4)
p_load argument will install + load the package if it's not in your lib else it will simply load it.
Someone suggested a not so elegant way around it, but actually it doesn't matter as long as it works fine.
install.packages('package','/Users/yourusernamehere/anaconda/lib/R/library')
I spent almost an entire morning looking for an answer to this problem. I was able to install the libraries on RStudio but not on Jupyter Notebook (they have different versions of R) The above solution "almost" worked, it's just that I found the Jupyter Notebook was trying to install in a different directory, and it will report what directory. So I only changed that and it worked as a charm... thanks to Dninhos
What worked for me is install.packages("package_name", type="binary").
None of the other answers have worked.