Installing Jupyter Notebook python package - version confusion - python

I usually work with pyCharm in which it is really easy to manage different python versions. (I use High Sierra, Mac)
In my settings I can see all of them and addon packages:
To be honest, I don't remember how I installed all of these, a bunch of them through brew though.
Now I am trying to run a Jupyter Notebook in python 3, it's using the python 3 kernel, but I am missing acp package.
So I pip install acp. ok.
The Notebook doesn't see the package. This makes me think it's not installing in the correct python version.
pip3 is not recognised as a command.
brew install python3 -> asks to update python 2 to version 3 (which I don't want).
I am quite confused now as how to intall the packages...

It may be installing with python executable your jupyter is not using.
you can directly install in jupyter shell by allowing python executable your jupyter is using:
import sys
!{sys.executable} -m pip install acp

To check your Python executables, you may open a terminal and type
touch ~/.bash_profile; open ~/.bash_profile
Then you will know which path your python exists in. Make sure to select the same path when you configure your project interpreter. Then you may like to upgrade your pip by typing in a terminal:
$ sudo pip install --upgrade pip
$ alias python=python3
$ python --version
Make sure python version is >3, after which that you may try:
pip3 install acp

Related

Linux Mint Changing current version of Python

I have installed python 3.7 but still using and showing version of python 2.7 . I want to change it to 3.. I searched it but ı can't did it.
You should not change your syslink python to use python 3 because it is most likely that your system is using that syslink to python 2 for its own tasks and processes, if you change that, you may broke your system.
As Sammy said in a comment, you should use python3 to use that version.
On the pip side, it is probably that your python 3 does not have pip include (it should have it, but I have seen a lot of Python 3 without it). You can check if you have pip doing: python3 -m pip. The -m param is used to execute modules of python installed.
If you do not have pip installed, you can install it following this (which I recommend because always work): https://pip.pypa.io/en/stable/installing/
That is:
Download a script to install pip: curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
Execute the script in order to install pip (with sudo because you're going to modify your system): sudo python3 get-pip.py
Now you should have pip installed and doing python3 -m pip again should show you the help of pip.
If you have pip already installed and no pip3 command in your system, you can always create an alias to python3 -m pip with the name pip3 and problem solved. Also if you don't know or do not want to create alias or executables in the /usr/bin folder, you can always keep using python3 -m pip.
PS: It is highly recommended to use virtualenvs when developing with python. If you do not know what it is, here it is a link to the docs: https://virtualenv.pypa.io/en/latest/

How can i make computer read a python file instead of py?

I have a problem with installing numpy with python 3.6 and i have windows 10 64 bit
Python 3.6.6
But when i typed python on cmd this appears
Python is not recognized as an internal or external command
I typed py it solves problem but how can i install numpy
I tried to type commant set path =c:/python36
And copy paste the actual path on cmd but it isnt work
I tried also to edit the enviromnent path through type a ; and c:/python 36 and restart but it isnt help this
I used pip install nupy and download pip but it isnt work
Try pip3 install numpy. To install python 3 packages you should use pip3
On Windows, the py command should be able to launch any Python version you have installed. Each Python installation has its own pip. To be sure you get the right one, use py -3.6 -m pip instead of just pip.
You can use where pip and where pip3 to see which Python's pip they mean. Windows just finds the first one on your path.
If you activate a virtualenv, then you you should get the right one for the virtualenv while the virtualenv is active.

Problems with installing matplotlib in python 3.6

I'm trying to teach myself python, and I feel out of my depth. To start, I am working on a mac which already comes with python 2.7 installed.
I installed python 3.6 recently and have been using it to teach myself the basics. I'd like to eventually learn how to produce mathematical plots in python, and I know I will need the matplotlib package to do that.
Following some advice online, I was told that python3 already comes with pip installed, which is what I thought I should use to install matplotlib. The advice said I should type the following into the mac terminal:
python3.6 -m pip install matplotlib
I typed this, and it seemed like the package was installing, but I ended up getting some sort of error code that said:
Command "python setup.py egg_info" failed with error code 1 in [folder].
I tried opening IDLE and typing "import matplotlib", but I got the error: "no module named matplotlib". I also tried typing "import matplotlib.pyplot as plt", but I got the same error.
Based on further research and this youtube video, I've decided to just install miniconda in order to have access to the matplotlib package.
The problem is, I'm not sure if I should somehow be uninstalling whatever was installed when I ran the code above to install matplotlib. I've actually run that line of code 3 or 4 times. Should I remove anything before installing miniconda? Also, I am running python 3.6, while miniconda is listed on the website as being for python 3.5. Does this mean it won't work for my version of python?
Running pip like that would install packages system-wide. I'm guessing it's failing because you're not running as root (i.e. the administrator user). But wait! Don't try again as root! Instead of installing packages, do it in a virtual environment. First create it:
virtualenv myenv
This creates a directory called myenv with a bunch of stuff in it (so make note of where you run this command). Whenever you want to use the virtual environment (like straight away!) you first need to activate it:
. myenv/bin/activate
Don't miss out that dot (followed by a space) at the beginning! As the other answer says, the first thing you should do in it is upgrade pip:
pip install --upgrade pip
Now you're ready install whatever else you like:
pip install matplotlib
One last note: The virtual environment is tied to a particular Python version. By default it uses the system's Python 2.7 installation, so to use a different one you need to specify it when you create the virtual environment, like this (if that Python version is installed system-wide):
virtualenv -p python3.5 myenv
Or like this (if that Python version is not installed system-wide):
virtualenv -p /path/to/my/installation/of/python3.5 myenv
While the virtual environment is activated, you don't need to specify the particular path/version of Python. Just run it like this:
python
I also encountered many problems during my installation.
It seems that version 2 of matplotlib is not compatible with Python version 3.
Finally, I succeeded by specifying version 3 of matplotlib as follows with the following command:
sudo apt-get install python3-matplotlib
Reference from the Matplotlib website:
https://matplotlib.org/users/installing.html#building-on-linux
Try upgrade setup tools
--upgrade setuptools
or
easy_install -U setuptools
or upgrade pip
pip install --upgrade pip
I ended up downloading anaconda and using the python interpreter that comes with it, as anaconda comes with matplotlib and many other python packages of interest.
the pip command typically is for the Python 2. use pip3 instead to install the libraries in the python 3.X path
This should work
pip3 install matplotlib
The solution that work for me in python 3.6 is the following
py -m pip install matplotlib
Matplotlib files are downloaded in ~/.local/lib/python3.6/site-packages/ and not in /usr/lib/python3.6/ .
Try the command:
sudo cp -r ~/.local/lib/python3.6/site-packages/* /usr/lib/python3.6/

How to install packages in different version of python?

I have a MacBook Pro that came pre-installed with python2.7. I later installed python3 and ipython notebook. I installed pip too to install packages, and am able to install packages and run program from python3. However, for another project I need to run code in python2.7, and I am not sure how to install it in python2.7 folder.
I tried using pip for installing packages to 2.7, but it kept giving error saying package already exists. When I check for version of python using --version, I see 2 pythons installed. However, when I check for pip and pip3, both seem to be in th same folder.
Any tips on how to install packages in python2.7, without making any changes to 3.3? I am using python3 and ipython notebooks for another project.
viveks-mbp:~ vivekyadav$ which pip
/Library/Frameworks/Python.framework/Versions/3.3/bin/pip
viveks-mbp:~ vivekyadav$ which pip3
/Library/Frameworks/Python.framework/Versions/3.3/bin/pip3
viveks-mbp:~ vivekyadav$ which python
/usr/bin/python
viveks-mbp:~ vivekyadav$ which python3
/Library/Frameworks/Python.framework/Versions/3.3/bin/python3
You can use the virtualenv to create a kind of sandbox.
$ virtualenv <work-directory>
$ source <work-directory>/bin/activate
The last command initiate your virtual environment, totally isolated from the system. So every pip command will install the package inside this directory.
But you have to run your application inside the virtual environment too.

Executing "python setup.py install" inside an iPython notebook

I recently downloaded some software that requires one to change to the directory with python files, and run python setup.py install --user in the Terminal.
One then checks whether the code is running correctly by trying from [x] import [y]
This works on my Terminal. However, when I then try from [x] import [y] in the notebook, it never works. So, this makes me think I must install the setup.py file within the iPython notebook.
How does one do this?
No, installing a python module in the terminal is sufficient. There is not such thing as installing within the IPython notebook.
Simply restart your IPython notebook after the install. If it still does not work, you are probably not using the same python interpreter between the two: check python version (which python), make sure you are not using a virtual environment, and that $PYTHON_PATH is not somehow different, etc.
You might be using the wrong version of the iPython notebook.
Perhaps you've been using ipython3 notebook instead of ipython notebook or vice-versa. If Python2.7 has the package you want, it won't work if you try to import it into the ipython3 notebook.
If there's a version mismatch then you can usually just get the relevant package using a sudo pip3 install package_name or sudo pip install package_name depending on the version you want.
Of course pip can be obtained by sudo apt-get install python3-pip for Python 3 and sudo apt-get install python-pip for Python2.7.

Categories