I wish to use anaconda distribution of ipython, but typing ipython at the terminal produces an error message:
Traceback (most recent call last):
File "/usr/local/bin/ipython", line 5, in <module>
from pkg_resources import load_entry_point
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 2603, in <module>
working_set.require(__requires__)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 666, in require
needed = self.resolve(parse_requirements(requirements))
File "/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/pkg_resources.py", line 565, in resolve
raise DistributionNotFound(req) # XXX put more info here
pkg_resources.DistributionNotFound: ipython==0.13.1
Adding PATH to .bash_profile as below produces the same error message. Asking which python produces //anaconda/bin/python, and which ipython produces /usr/local/bin/ipython. How can I fix this such that ipython launches anaconda ipython?
# MacPorts Installer addition on 2012-11-03_at_23:50:01: adding an appropriate PATH variable for use with MacPorts.
export PATH=/opt/local/bin:/opt/local/sbin:$PATH
# Finished adapting your PATH environment variable for use with MacPorts.
# Add colors to terminal
export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad
# added by Anaconda 1.6.1 installer
export PATH="//anaconda/bin:$PATH"
export PATH=/anaconda//bin/isympy:$PATH
# added to Homebrew: bad command
export PATH=/usr/local/bin:$PATH
Update: I updated anaconda and ipython using conda update as suggested, but still get the same error message.
Update 2: Thanks for all the suggestions. I modified /usr/local/bin/ipython as follows:
#!//anaconda/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'ipython==1.1.0','console_scripts','ipython'
__requires__ = 'ipython==1.1.0'
import sys
from pkg_resources import load_entry_point
sys.exit(
load_entry_point('ipython==1.1.0', 'console_scripts', 'ipython')()
)
Now which ipython produces //anaconda/bin/ipython, and ipython launches.
Your problem is in your $PATH. If you look at your traceback, it's running /usr/local/bin/ipython - this is the one that is installed by Homebrew, and not by Anaconda. (Anaconda installs everything into /anaconda/bin.)
The reason this is getting picked up is because the very last line of your .bash_profile sticks /usr/local/bin at the front of your path. This means that the ipython that you installed via Homebrew is masking the one that's installed by Anaconda.
You have two options:
Uninstall the ipython that Homebrew installed, and just use Anaconda for your Python packages.
In your .bash_profile, move the Homebrew PATH modification line above the Anaconda one. This way, Anaconda's ipython, python, and various other Python commands will take precedence.
Remember, if you change your .bash_profile, you need to close your Terminal and start a new one for the changes to take effect.
It looks like your path is completely ok. Notice that the error comes from "/usr/local/bin/ipython". It is not a bash error, it is more likely an error involving setup_tools, or pip, that is Python packaging tools. Bash finds ipython and executes ipython startup file but encounters an error there.
The error appears to be saying that your version of ipython is incompatible. Have you tried doing something like this?
conda update conda
conda update ipython
Updaing conda and ipython is recommended in iPython documentation. Perhaps this will fix the problem. If not, then add an information saying that you updated conda and ipython to your question.
One possible reason is that there are multiple ipython versions installed e.g., brew might install to /usr/local/bin, conda might install to /anaconda/bin (it is just a guess). The advice from similar issue is to remove all ipython installation completely and install the one that you will use.
Ensure you check the path to the Python executable specified at the start of the script. When I installed iPython it was defined as:
#!/usr/bin/python
Instead of:
#!/usr/local/bin/python
Hence the default OS X install of Python was being used instead of my brew installed version.
For me was slightly different because even with Anaconda installed wasn't able to find the command or to run ipython and wasn't able to find the PATH.
My solution was to run these commands:
nano ~/.bash_profile
export PATH="/anaconda3/bin:$PATH"
source ~/.bash_profile
and then to check conda version:
conda
and I update conda and ipython running:
conda update conda
conda update ipython
Hope this could help someone.
This helped me: https://stackoverflow.com/a/49925193/3351569
Related
for my homework we need to use jupyter notebook to run an .ipynb file. I use Mac and I used pip install jupyter to install it using terminal, which was successful. However when I tried to open it using the commandjupter notebook I get this error. Any ideas? Thanks.
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.6/bin/jupyter-notebook", line 5, in
from notebook.notebookapp import main
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/notebook/notebookapp.py", line 76, in
from .base.handlers import Template404, RedirectWithParams
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/notebook/base/handlers.py", line 24, in
import prometheus_client
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/init.py", line 3, in
from . import (
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/gc_collector.py", line 43, in
GC_COLLECTOR = GCCollector()
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/gc_collector.py", line 14, in init
registry.register(self)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/registry.py", line 26, in register
names = self._get_names(collector)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/registry.py", line 66, in _get_names
for metric in desc_func():
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/gc_collector.py", line 36, in collect
collected.add_metric([generation], value=stat['collected'])
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/prometheus_client/metrics_core.py", line 126, in add_metric
self.samples.append(Sample(self.name + '_total', dict(zip(self._labelnames, labels)), value, timestamp))
TypeError: new() missing 1 required positional argument: 'exemplar'
From your terminal out screen grab, I can see that you are not in a virtual environment which would mean that you are using global python.
Three things to check and or consider:
1. Python Version (management and checking).
To avoid the type of error that you are seeing- creating dependency issues of your versions of python, it may be an idea to use a package manager like conda or use virtual environments and install within them.
2. Proper use of pip install:
If you do not want to use vnev's or a package manager like conda perhaps double-check that you have installed on the correct version of python and install jupyter on the version of python you want to use.
python3.6 -m pip install jupyter
3. Environment Management:
There are a number of different options for managing the python version some people like to create virtual environments within your present working directory and active them using:
python3.6 -m pip install virtualenv
python3.6 -m venv env_name
source env_name/bin/activate
Once activated your terminal will show:
(env_name) jeffmpro....
You can then pip install jupyter inside this environment and this will then run using:
jupyter notebook
If you want to manage the python version and virtual environments globally using shims you can do this using a package called pyenv:
https://github.com/pyenv/pyenv
https://github.com/pyenv/pyenv-virtualenv
I would also use homebrew on mac to manage installations in the command line.
https://brew.sh/
Hope this helps :-)
The correct answer is actually what came out in the comments, I'll report it here for future viewers:
pip install jupyter
pip install notebook
jupyter-notebook your-file.ipynb
See you!
I've attempted to start writing Python in WSL, but the whole experience has been super messy. To install packages, I know I want to use pip3, but any pip3 commands result in
Traceback (most recent call last):
File "/usr/bin/pip3", line 9, in <module>
from pip import main
ImportError: cannot import name 'main'
My work-around has been to use the following command to install, which has worked:
python3 -mpip install --user somePackageName
My real confusion now comes from the fact that the which command is not locating packages installed by the above command. However, I know they are there as they appear when I run 'python3 -mpip freeze'. Is this because they are installed locally?
(Also If anyone has experience with Python and pip in WSL and could weigh in on how to go about configuring my Python environment, in order to avoid these types of issues, that would be super helpful.)
Thanks!
Try: python -m site
(perhaps replacing python by python3, etc)
You should get a short output with the following block,
From Windows:
sys.path = [
'<your current working directory>',
'C:\\Python38a2\\python38.zip',
'C:\\Python38a2\\DLLs',
'C:\\Python38a2\\lib',
'C:\\Python38a2',
'C:\\Python38a2\\lib\\site-packages',
]
From WSL:
sys.path = [
'<your current working directory>',
'/usr/lib/python37.zip',
'/usr/lib/python3.7',
'/usr/lib/python3.7/lib-dynload',
'/home/<username>/.local/lib/python3.7/site-packages',
'/usr/local/lib/python3.7/dist-packages',
'/usr/lib/python3/dist-packages',
]
That's where you'll want to look for installed packages.
The order here is the import precedence (earlier entries "trump" later ones)
For pip installed packages, you'll generally want to look in the site-packages directory.
For <package manager> installed packages you'll generally want to look in the dist-packages directory.
Lastly, which is generally used to find executables on your $PATH environment variable (and, at least for me, requires that they have the executable bit set to appear in the results).
Here, you're looking for something different, modules or packages that are importable by Python. In other words, modules or packages on your $PYTHONPATH.
These are two different types of "path"s.
Inside your interpreter, $PYTHONPATH maps to sys.path and $PATH maps to os.environ['PATH'].
I was running into a problem while trying to install anaconda and python 3.7 on MacOS. After I installed anaconda, every time I open my Terminal, the following message shows up:
Fatal Python error: initsite: Failed to import the site module
Traceback (most recent call last):
File "/Users/s/anaconda3/lib/python3.7/site.py", line 570, in <module>
main()
File "/Users/s/anaconda3/lib/python3.7/site.py", line 563, in main
execsitecustomize()
File "/Users/s/anaconda3/lib/python3.7/site.py", line 502, in execsitecustomize
import sitecustomize
File "/usr/local/lib/python2.7/site-packages/sitecustomize.py", line 16, in <module>
' You should `unset PYTHONPATH` to fix this.')
File "/Users/s/anaconda3/lib/python3.7/_sitebuiltins.py", line 26, in __call__
raise SystemExit(code)
SystemExit: Your PYTHONPATH points to a site-packages dir for Python 2.x but you are running Python 3.x!
PYTHONPATH is currently: "/usr/local/lib/python2.7/site-packages:"
You should `unset PYTHONPATH` to fix this.
Of course I tried to unset the PYTHONPATH, but it doesn't work: every time I open up the Terminal again, the messages appears again.
Can anyone help me with this issue?
Thank you for your help
If you loaded pythona and anaconda that helps a lot. After you load python3.7 be sure to type 'which python3.7' to get its location. Now you want to create a virtual environment for python3.7. Anaconda makes this easy. You can type the following commands on the terminal in your home directoty
conda create -n myenv python=3.7
where myenv is the name of your virtual environment. It can be any name you please. After that you must activate that environment by typing:
source activate myenv
After activating the environment just run python or python3 from the command line. It should work now. Additional instructions for creating a virtual environment using Anaconda can be found
here or here. There are numerous other sites. Just google some combination of 'create virtual environment anaconda mac.
I am trying to install TensorFlow by Anaconda(My Python is 3.5.2 edition).
When I run:
(tensorflow)C:> pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.1-cp35-cp35m-win_amd64.whl
According to the guide in Tensorflow.org, the following tips emerge:
Exception:
Traceback (most recent call last):
File "C:\Users\Anaconda3\lib\site-packages\pip\basecommand.py", line 215, in main
status = self.run(options, args)
File "C:\Users\Anaconda3\lib\site-packages\pip\commands\install.py", line 317, in run
prefix=options.prefix_path,
File "C:Anaconda3\lib\site-packages\pip\req\req_set.py", line 742, in install
**kwargs
File "C:\Users\Anaconda3\lib\site-packages\pip\req\req_install.py", line 831, in install
self.move_wheel_files(self.source_dir, root=root, prefix=prefix)
File "C:\Users\Anaconda3\lib\site-packages\pip\req\req_install.py", line 1032, in move_wheel_files
isolated=self.isolated,
File "C:\Users\Anaconda3\lib\site-packages\pip\wheel.py", line 346, in move_wheel_files
clobber(source, lib_dir, True)
File "C:\Users\Anaconda3\lib\site-packages\pip\wheel.py", line 324, in clobber
shutil.copyfile(srcfile, destfile)
File "C:\Users\Anaconda3\lib\shutil.py", line 115, in copyfile
with open(dst, 'wb') as fdst:
PermissionError: [Errno 13] Permission denied: 'C:\\Users\\Anaconda3\\Lib\\site-packages\\numpy\\core\\multiarray.cp35-win_amd64.pyd'
I don't know what causes this error. Can someone help me with that?
Might be late but I got the exact same error and this is what happened. My issue was that there was some file that was being used inside numpy that was locked by anaconda(or some other process) I guess and tensorflow needed that file. Hence I got permission denied. All I did was shut down every process anaconda, jupyter etc and ran:
1) conda update --all
2) pip install --ignore-installed tensorflow
Open your cmd as an administrator and do not activate tensorflow. Just simply fire commands from your cmd. For eg: C:\\> pip install --ignore-installed tensorflow (your directory may vary) should be fine. Let me know if you get stuck.
Run the cmd console as adminstrator, then execute you installation.
You can key cmd in run or Cortana, then right click the console and select run as adminstrator.
I had the same problem on several Windows machines (W7, W8.1 and W10). At last I solved the problem in the same way in all of them:
Uninstall Anaconda
Download Anaconda3-4.2.0 from Anaconda Installer Archive. This version of Anaconda includes Python 3.5.2. TensorFlow only supports version 3.5.x of Python on Windows.Although you can create an environment with version 3.5 of Python, I recommend installing Anaconda 4.2.0
Install Anaconda3-4.2.0 on a different drive than the Windows drive, for example in D:\Programdata\Anaconda3. Although installing on another drive is no longer necessary, better to select to install for all users.
Open an Anaconda Promp with administrator privileges and:
Create a environment named tensorflow by invoking the following command:
conda create -n tensorflow python=3.5
Activate the conda environment by issuing the following command:
activate tensorflow
Install TensorFlow:
conda install -c conda-forge tensorflow
Install Jupyter and Spyder at least, but surely you will need to install scipy too for example:
conda install spyder
conda install jupyter
After that you can check if all is correct by invoking python and trying the next program:
import tensorflow as tf
hail = tf.constant('Hello World')
session = tf.Session()
print(session.run(hail))
Now you can check if Spyder works. Exit from Python, invoke Spyder from Anaconda prompt and try de program.
If you have any problem with iPython, install it on the tensorflow enviroment.
conda install ipython
If you want to update spyder write the following command:
conda update spyder
Remember to launch Spyder from the Anaconda prompt after you have activated the tensorflow enviroment.
I hope it works for you.
Edited: TensorFlow, since version 1.2.0, is compatible with Python 3.6, so you can already install the latest version of Anaconda (4.4.0 | Release Date: May 31, 2017), which incorporates Python 3.6.
Maybe because there are other processes using tensorflow. Try to close these processes and then install or update tensorflow.
I had the same error and fixed it by running conda update --all first.
BUt be careful with conda update:
(https://github.com/ContinuumIO/anaconda-issues/issues/830)
Updating packages
conda: 4.0.5-py35_0 --> 4.1.1-py35_0
conda-env: 2.4.5-py35_0 --> 2.5.0-py35_0
matplotlib: 1.5.1-np110py35_0 --> 1.5.1-np111py35_0
mkl: 11.3.1-0 --> 11.3.3-1
mkl-service: 1.1.2-py35_0 --> 1.1.2-py35_1
numexpr: 2.5-np110py35_0 --> 2.5.2-np111py35_1
numpy: 1.10.4-py35_0 --> 1.11.0-py35_1
pandas: 0.18.0-np110py35_0 --> 0.18.1-np111py35_0
scikit-learn: 0.17.1-np110py35_0 --> 0.17.1-np111py35_1
scipy: 0.17.0-np110py35_0 --> 0.17.0-np111py35_4
will break Scripts/activate.bat under Windows if the install path contains spaces. (Replacing activate.bat with the original one just works fine.)
I had the same error for python 3.6, ran cmd through admin mode, worked like a charm.
I had permission denied problem on windows but this worked for me:
right click on cmd or git console > run as administrator
pip install tensorflow
I had a file locked up from a crashed Jupyter run. Rebooted and reinstalled as Adm. All good.
I solved problem by below command
pip install --upgrade
https://storage.googleapis.com/tensorflow/windows/cpu/tensorflow-1.0.1-cp35-cp35m-win_amd64.whl
I am working in windows7. and have pycharm installed along with anaconda spyder. I have been working in anaconda spyder for very long but now I want to use pycharm as it is better and easier to create projects.
so I created a new virtual environment and started a new project. Now when I try to specify my package installs via requirements.txt I get this error.
Traceback (most recent call last):
File "C:\Program Files\JetBrains\PyCharm Community Edition
2017.2.4\helpers\packaging_tool.py", line 192, in main
retcode = do_install(pkgs)
File "C:\Program Files\JetBrains\PyCharm Community Edition
2017.2.4\helpers\packaging_tool.py", line 109, in do_install
return pip.main(['install'] + pkgs)
AttributeError: module 'pip' has no attribute 'main'
I need help in fixing this. Nothing online has worked and I dont know where the problem is. I am using pip version of 10.
Should I uninstall my anaconda python. is it possible that it is interfering with pycharm?
Thanks
pip.main is no longer supported, and, as of 10.0, was removed. (See this documentation on what to do instead, but that probably isn't directly relevant to you—you're just trying to use PyCharm, not write your own replacement for PyCharm…)
Anyway, any graphical package manager that was built around calling pip.main, as PyCharm's used to be, breaks with 10.0. IIRC, PyCharm changed its code to handle this before 10.0 even went live. However, you're using an old version of PyCharm, which doesn't have those changes.
The obvious solution is to update PyCharm.
If you don't have any reason to use an old version, just get the latest version (as of today, 2018.1.4) by auto-updating, or by downloading it from the main Download page.
If you need to stick with an old version for some reason, get the latest 2017.2 version (as of today, 2017.2.7) from the Previous Releases page. This should be essentially the same as the version you have, but with critical fixes backported (which hopefully includes working with pip 10, although I haven't tested that).
The other option is to downgrade pip to a pre-10.0 version.
You can specify a version as just <10. If you want to specify one explicitly, I think 9.0.3 should be the last-ever 9.x version, but, to be safe, check the version history.
I don't know if downgrading pip with pip is supposed to work, but it actually did seem to work when I tried it on a test environment:
python3 -m pip install --force-reinstall 'pip<10'
If not, you can uninstall it and reinstall it:
python -m pip uninstall pip
python -m ensurepip
python -m pip install -U 'pip<10'