i install conda installed and Python installed seperately - python

i have Conda installed and Python installed separately, when i run .py file it is referencing to python's packages not from Conda so some pkg are missing(pandas), Conda has pandas but not Python. all default installations are go to Conda pkg files. how do i install pandas to Python that is not in Conda?

To run a file from conda, simply go to your anaconda prompt and cd into the drive. Similarly, you can search for your python prompt from the start bar and run code from there.
To install pandas into your python installation type:
pip install pandas
If you are running code from an IDE or code editor, you need to go into your settings and change the default runtime environment to anaconda. Even easier, open your anaconda navigator and then run your editor from there.
Your conda installation can't not have python, although it might be running the wrong version of python for your code. To change the version of python type:
conda install python=$pythonversion$
into your conda prompt.

Related

Issue with installing python modules

I am pretty new to python. Just been working through some online tutorials on udemy. I seem to have an issue with pip installing modules.
I've tried reinstalling them.
Upgrading my python version.
In VS I always just get module not found.
If I do it in the cmd prompt this is what I get below.
You are currently working on the base environment of your computer. For safety, you can first create a new virtual environment with
python3 -m venv -n new_env
So that you won't corrupt any default installations. Then, activate it with
source new_env/bin/activate
And update the pip and setuptools with
pip3 install --upgrade pip
pip3 install --upgrade setuptools
Finally, install numpy via
pip3 install numpy
However, I would recommend using Anaconda to build your virtual environment. When you install Anaconda and make sure it is included in the path of your terminal, all you need to type is
conda create -n new_env python=3.7 numpy
and it will automatically build the wheel for numpy. Here, "new_env" is just an example for a virtual environment name, and Python version 3.7 is also an example.
You can then, activate this conda environment by
conda activate new_env
To use this virtual environment, which you built either with "venv" or "conda", you should locate and activate this environment from the project interpreter settings in VS .
Finally, I would also recommend considering Pycharm IDE which can also help you with creating a virtual environment and installing packages in it.
It seems that you already have the packages installed. Using VS, please, be sure that you selected the correct Python interpreter (https://code.visualstudio.com/docs/python/environments)

Python - package not found although it is installed

I have the following version of python
import sys
print(sys.version)
3.6.5 | packaged by conda-forge | (default, Apr 6 2018, 13:44:09)
[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]
I installed a package with the following command
pip install wfdb
It is succesfully installed because when I then write the command:
pip show wfdb
The following information appears
Location:
/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages
However, when I type the command import wfdb in Python notebook or the version of python in terminal, I get the following message
No module named 'wfdb'
Does it have to do with the path on which python is checking where the packages are? How to check this and how to change it?
You have (at least) 2 Python installations, one managed by Anaconda, the other what appears to be an official Python.org Mac build installed system-wide. The pip command on the command-line is the one tied to the Python.org Mac build.
pip is a script that is tied to a specific Python installation, and there can be multiple versions of the script installed in different locations, and is usually also installed with pipX and pipX.Y to match the X.Y version indicator of the Python version it is tied to. For Python 3.6, that means the same script would also be available as pip3 and pip3.6. (This also means that pip can be connected to Python 2 or Python 3, depending on your exact OS setup. It is not a given that pip, without a version number, installs into Python 2.x as some answers may claim).
Note that when you run a command without a path in your shell, (such as pip as opposed to /usr/bin/pip), you are asking your shell to find the command for you in a number of locations, listed in the PATH environment variable. The first location in the PATH list with that command is then fixed. which -a <command> would tell you all possible PATH-registered locations that the command can be found in. You can always use the full path to a command to bypass the PATH search path.
You can always verify what Python version the pip command is connected to with:
pip -V
which will output the version of pip and the location it is installed with. It'll print something like
pip pipX.pipY path/to/pythonX.Y/site-packages/pip (python X.Y)
where pipX.pipY is the pip version number and path/to/pythonX.Y tells you what Python installation this is for.
You can try to match this with the Python version by running
python -m site
which outputs the Python module search path for that Python version. Python can be run with python, pythonX and pythonX.Y too, and is subject to the same PATH search.
Note the -m switch there, that instructs Python to find a module in it's module search path and execute it as a script. Loads of modules support being run that way, including pip. This is important as that helps avoid having to search for a better pip command if you already can start the right Python version.
You have several good options here:
Since you are using Anaconda, you could look for a conda package for the same project. There is such a package for wfdb. Install it with
conda install wfdb
Anaconda aims to give you a wider software management experience that includes a broader set of software options than just the Python PyPI ecosystem, and conda packages usually manage more things than just the Python package.
Conda packages are usually maintained by a different set of developers from the package itself, so there may be a newer version available on PyPI (requiring pip install) than there is on Conda.
This is not an option for all Python packages, if there is no conda package you have to use pip. See Installing non-conda packages.
you can use the conda command to create a conda environment. Once you have an environment created, you can activate it with
source activate <name_of_cenv>
to alter your PATH settings. With the envirnoment 'active' the first directory listed on your PATH is the one for the conda environment and the pip command will be the one tied to that environment.
Note that a conda environment gives you an isolated environment for a specific project, keeping the library installation separate from the rest of your Python packages in the central site-packages location. If you want to install a package for all of your Anaconda Python projects, don't use a conda environment.
Use the Anaconda Python binary to run pip as a module; when you can run /path/to/python or pythoncommand to open the right Python version, you can use that same path to run /path/to/python -m pip ... instead of pip ... to be absolutely certain you are installing into the correct Python version.
Look for a better pip command, with which -a pip or which -a pip3.6, etc. But if you already know the Python binary, look in the same bin location for pip. If you have anaconda/bin/python, then there probably is a anaconda/bin/pip too.
As you can read here:
pip3 and pip would make a difference only when you are not using any
environment managers like virualenv (or) conda. Now as you are
creating a conda environment which has python==3.x, pip would be
equivalent to pip3.
For this reason it could be you did not activate your Conda environment before installing required packages and running your code.
Activate the new environment:
On Windows:
activate myenv
On macOS (this should be your option) and Linux:
source activate myenv
NOTE: Replace myenv with the name of the environment.
which python
gives the you the PATH to python
and then /path/to/python -m pip install thepackagetobeinstalled
Many thanks #MartijnPieters
You have installed python2.x package and you're using python3.x. Try:
pip3 install wfdb
If you don't have pip3 run:
[apt-get/yum] install python3-pip
You can see what packages you have currently installed by running:
pip freeze
and for python 3.x packages
pip3 freeze
Please remember each time you install a Python package, it will be placed in the directory for one particular Python version. Hence your error.

How to install Python packages in a specific environment?

I installed Anaconda3 so I can create environments and install different packages in each environment. But I fail to understand the difference between the Python in
/usr/bin/python
and
/opt/anaconda3/bin/python
I can seem to access Python 3.6.5 Anaconda from both, why is that? And, what is the difference between both?
Furthermore, I would like to install packages to a single Python environment only.
When you are running python in the terminal, it is looking up your default path to your the python command. In this case, anaconda probably put a line in your shell profile specify the path to the anaconda version, which is why you are seeing it in the interpreter when you run python from either directory.
Secondly, you can set up a conda environment to download app specific dependencies without interfering with your default set up by
conda create --name myenv
source activate myenv
conda install packagename
This will install it in the myenv environment only. To deactivate the environment just run
source deactivate
Here is the documentation on that https://conda.io/docs/user-guide/tasks/manage-environments.html
Judging by your path, you are using Linux which comes with python installed. So /usr/bin/python is default and you have installed the other one later.
For the environments use https://conda.io/docs/user-guide/tasks/manage-environments.html to activate the desired environment, then you can pip install or conda install the packages and it will be places safely only in that environment. Note that spyder icon runs the root environment by default and you have to run it from terminal after activating one of the environments.
Edit:
I'm not sure why you want to use cd to change the python version. I suggest use aliases. I guess you are just changing the path but running the same version of the python anyway. Take a look at this question:
Two versions of python on linux. how to make 2.7 the default
I wanted to create a new virtual environment to install new packages. Following worked for me:
Commands are executed in Jupyter Notebook (OS: Ubuntu 16.04 LTS)
Upgrade pip:
!pip install --upgrade pip
Install virtual environment:
!pip install virtualenv
Select version of Python you want to use in new environment:
I wanted to create an environment with Python version 3. Naming it as Python3_xyz:
!virtualenv -p python3 Python3_xyz
After execution, this will create a folder with the same name in the current working directory (i.e. the location where Jupyter notebook is present)
Create a new option with the name of the created environment
And finally, run the following command:
!python -m ipykernel install --user --name=Python3_xyz
This will create a new option with the name Python3_xyz in the menu from where we create a new notebook.
NOTE: One can run above commands from the terminal as well just don't use '!' before the commands.
This question is bit dated, but since I faced a similar issue, what worked for me might help someone!
I did pip install requests from within my conda environment, but failed to import requests even after trying out everything.
What worked for me: run python -m pip install requests or python3 -m pip install requests within you environment. This installed requests successfully for me.

Anaconda As Python in Debian Linux Terminal

I am working on a project in python on a Debian 8 VM. To work on the project further I need to install matplotlib 1.5.1. When I attempt to upgrade the current version (obtained through apt-get) or install I am told that I need freetype and png. When I go to install freetype using this link:
http://www.linuxfromscratch.org/blfs/view/svn/general/freetype2.html
After installing and entering the proper commands, I go to try to install matplotlib again and receive the same error.
I tried to install Anaconda3 because it comes with freetype and basically every package that I need for my project. But after running the .sh file I was unable to change my python to use anaconda as the interpreter. How can I do this?
Thanks!
[UPDATE]
I am having to go into my anaconda3 file, then run source bin/activate ~/anaconda3/ Is there anyway to create an alias that would do all this?
You have to first create a conda python environment:
/path/to/conda/bin/conda create --name myenv python=3
(see http://conda.pydata.org/docs/using/envs.html)
When the environment has been created you simply activate it as follows:
/path/to/conda/bin/source activate myenv
Thereafter the system will run python from the conda environment you specified and not from the standard location.

IPython Notebook - python3 not found after uninstalling Anaconda3 for Anaconda

I uninstalled Anaconda 2.3 with Python 3.4.3 and then installed the same Anaconda version with Python 2.7.10.
When I open a notebook via $ ipython notebook "Example Notebook.ipynb" it tries to use the python3 kernel as opposed to opening with the installed python2. Of course I get the error python3 kernel not found.
How can I get ipython notebooks to open with the python2 kernel? I've tried to uninstall ipython and ipython notebook, then delete .ipython and .jupyter from my user directory in case there were any defaults set in these folders, then reinstalled both. Still get the same problem.
Any help would be appreciated
You can install several python versions alongside each other. Just create another environment (replace "all my packages" with the names of the packages).
conda create --name mypy_27 python = 2.7
or
conda create --name mypy_34 python = 3.4
afterwards you can activate the environments by typing
source activate mypy_34
if you then do
conda install "all your packages"
you install the desired packages in the active environment.
You can do much more.

Categories