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.
Related
By using pip, I can successfully install new packages in ipython running in the Spyder environment. All I need to run is this:
!python -m pip install mypackage
However, trying to uninstall packages doesn't seem to work, at all. When I run:
!python -m pip uninstall mypackage
The console goes into a state of hanging. It's not strictly 'hanging' because neither Spyder nor the console hangs but the command just isn't returning anything
I am attaching a screenshot to help explain what I mean. The screenshot shows what happens AFTER I have pressed ENTER on this line - and nothing happens!
Does anything know why?
You should not use pip with Spyder. It can break your whole distribution. Spyder is part of the Anaconda package and you should use the conda command instead of pip. The conda command works similar to the pip command. Instead of pip install package you'd use conda install package.
(Spyder maintainer here) Both pip and conda are not meant to be run inside one of our IPython consoles because they expect to be running in a real system terminal (xterm, Terminal.app or cmd.exe).
In this case, pip expects input from the user (the confirmation that he/she really wants to uninstall a package). That confirmation can't be displayed in our consoles and it makes it looked like its blocked.
What you could do is to pass the -q option to pip to avoid confirmation. But in general it's a very bad idea to use pip and conda inside our consoles for the reasons I stated above.
I have a windows 10 64 bit machine, i installed spyder with pip and it could not work. so to uninstall i just used this command
pip uninstall spyder
however, if spyder has been installed with alongside Anaconda, Uninstalling Anacanda will delete its all packages including spyder.
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
I installed pipenv by following the instructions here. From the Windows command prompt I ran
pip install --user pipenv
which returned the message
Successfully installed pipenv-5.3.3
Now I want to install the requests package using pipenv, so I ran
pipenv install requests
but this returned
'pipenv' is not recognized as an internal or external command,
operable program or batch file.
I have added the path
C:\Users\Robert\AppData\Roaming\Python\Python35\site-packages
to my Windows path environment variable, but I still receive the same error.
How can I install the requests package using pipenv?
EDIT: As I have remnants of Python 3.5 and Python 3.6 on my system, I'm going to uninstall everything and start anew. (I've just started learning Python and I want to keep this as simple as possible.)
I have a similar setup and faced a similar problem, but the solution I found was fairly simple. All of my PATH variables were already correct (from Python 3 the Windows Installer automatically does all of this).
The problem
The problem actually arises because of conflicting installations of virtualenv.
Fix
To address this problem you need to simply run the following commands:
First, remove your current version of virtualenv: pip uninstall virtualenv
Then, remove your current version of pipenv: pip uninstall pipenv
When you are asked Proceed (y/n)? just enter y. This will give you a clean slate.
Finally, you can once again install pipenv and its dependencies: pip install pipenv
This will also install the latest version of virtualenv.
Testing if it worked
Just enter pipenv --version in the command prompt and you should see the desired output.
Notes
I know this sounds the mundane, but it is actually the solution for Windows systems. You do not need to modify any of your system environment variables (please do not add site-packages to your environment variables).
python -m pipenv may work for you, (or python3 -m pipenv or py 3 -m pipenv) this is telling python to run the module pipenv instead of the terminal shortcut which sometimes doesn't install properly.
Just to show they are equivalent when I installed pipenv and run which pipenv it points to a file like /Library/Frameworks/Python.framework/Versions/3.6/bin/pipenv which looks like this:
#!/Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
# -*- coding: utf-8 -*-
import re
import sys
from pipenv import cli
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])
sys.exit(cli())
so it removes .pyw or .exe from the executable name then call pipenv.cli.cli(). It is likely there is a file like this on your machine it just didn't add python's /bin folder to your system PATH so it isn't accessible, there is usually a warning when installing python if this happens but no one checks those. :P
the module pipenv.__main__ which is run when using python -m pipenv looks like this:
from .cli import cli
if __name__ == '__main__':
cli()
Which calls pipenv.cli.cli(). So this main module absolutely does the same effective thing.
to solve this problem i need to start my CMD as administrator.
pip uninstall pipenv
pip install pipenv
To test this new configuration, you can write pipenv --version
Use python -m pipenv instead of just pipenv, it should work. Best of luck to you.
Try adding the following to Path environmental variable:
C:\Users\Robert\AppData\Roaming\Python\Python36\Scripts
instead of the \site-package, as that is where pipenv.exe is installed (at least for me).
use this cmd solve my problem :
python -m pipenv install django==2.1
Many thanks to #Srivats Shankar. In case you have tried what he said and it did not work, hope you did not forget to check your python path? If you have more than a single python version installed, doing pip uninstall virtualenv or pip uninstall pipenv might not help solve the problem.
Every python version is generally supposed to have its own pip installed. What you would do in this case is:
`-python -version_to_uninstall_virtualenv_from -m pip uninstall virtualenv; py --version -m pip uninstall virtualenv
-python -version_to_uninstall_pipenv_from -m pip uninstall pipenv; py --version -m pip uninstall pipenv`
Then you install pipenv with a similar command:
`-python -version_to_install_pipenv_on -m pip install pipenv; py --version -m pip uninstall pipenv`
I had an error like you sed and I just reinstalled pipenv and it fixed.
I used this command:
pip install pipenv
Instead of
C:\Users\Robert\AppData\Roaming\Python\Python35\site-packages
it should be
C:\Users\Robert\AppData\Roaming\Python\Python36\Scripts
after that, try closing and reopening the terminal
check warnings after installing pipenv. sometimes pipenv location not registered in environment variables.
I noticed several different situations with multiple python versions installed.
A preferred solution would be to use:
python -m pip install pipenv
This command for Python3.7 instance generates executables in
C:\Users\XXX\AppData\Local\Programs\Python\Python37\Scripts and it made setting up other packages easier.
Windows is not officially supported, I think.
ref: https://github.com/kennethreitz/pipenv/issues/70
Please check that pipenv is installed in your system by run following command in command promt:
pipenv --version
If it returns error, so please install again and set environment variable path in your system
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/
I'm trying to use neovim with deoplete and UtilSnips. Both requires Python support from nvim.
I followed the instructions in :help nvim_python to set the support but the output of :echo has('python') or :echo has('python3') are both 0.
On nvim-startup I get the message UltiSnips requires py >= 2.7 or py3 and for deoplete It requires Neovim with Python 3 support ("+python3").
My python (2.7.10) and python3 (3.4.3) are both installed with homebrew. The neovim module is installed over pip and pip3 with install neovim but nvim can't find it, even when I set the let g:python_host_prog path in nvimrc.
I don't know what I am able to do anymore, has anyone an idea whats wrong with it?
Please follow the instruction on https://neovim.io/doc/user/provider.html#provider-python to setup the python interpreter for neovim.
First, install pynvim (previously, it was named neovim, but that has been changed) plugin
pip3 install pynvim
Print g:loaded_python3_provider
echo g:loaded_python3_provider
" for python 2.x use the following
" echo g:loaded_python_provider
If it returns 1, the python is not setup for neovim. In your ~/.config/nvim/init.vim file, set the python interpreter
let g:python3_host_prog='/path/to/python3'
" for python2, use the following instead
"let g:python_host_prog = '/path/to/python2.7'
I encountered the same problem lately. Here are the steps adapted from answer of #VforVitamin where I made it working.
Assuming python2 and python3 are installed.
Install neovim plugin pip3 install neovim.
Open neovim.
Execute command :UpdateRemotePlugins.
Restart neovim.
I had the issue myself because I used neovim inside virtualenv. If so, make sure to pip install neovim inside your virtualenv, and make sure that import neovim works in the python interpreter.
If that doesn't help, you can try and run neovim with debug messages (neovim -V3, or any other logging level) and see what you can pick from there.
I bet you have a line in your init file that starts with "set runtimepath=".
Change it to "set runtimepath+="
If when you try
let [interp, errors] = provider#pythonx#Detect(2)
From the docs at
https://github.com/neovim/neovim/wiki/Troubleshooting#python-support-isnt-working
You get errors, could be that you have your VIM environment variable pointed to the wrong (probably vim74) runtime directory.
Neovim needs pythonx.vim from the runtime/autoload/providers/ folder to load a python interp. Vim74 doesn't provide this file.
If you have an env. variable of VIM (with a path), it will use that as your location of your runtime files - I had my set to /usr/share/vim/vim74, changing it to the location of neovim worked. I guess there is a compile time option to point to the correct location too.
I was with the same problem and the solution actually cames from the question.
What I did was:
pip install --upgrade pip
pip3 install --upgrade pip
sudo pip install setuptools
sudo pip3 install setuptools
sudo pip install neovim
sudo pip3 install neovim
After it, enter in neovim and :UpdateRemotePlugins. Close it and open again.
After these steps I had neovim working properly.
Edit:
For those using Arch Linux, we have a peculiarity about Python. The steps are:
Install pip (python3) and pip2 (python2): pacman -S python-pip python2-pip
Instead of pip3, you should use pip2
Beyond this minor difference, the rest of commands work pretty much the same way.
As pointed out by #fwalch, the documentation has changed to https://neovim.io/doc/user/provider.html#provider-python.
Neovim comes shipped with Python3 enabled, but you need to install the pynvim module in order to use Neovim Python3 plugins:
python3 -m pip install --user --upgrade pynvim