I am trying to use a Python program written for Python 2.7. I am using a Macbook Pro running Catalina. The program is here: https://github.com/geoss/censumander. The program has two Jupyter Notebooks to practice with. I have Anaconda 4.9.2 installed and pip 20.2.4. When I open Jupyter Notebook it defaults to Python 3 and has no kernel option to change to Python 2. I have used the guide here to try to install the Python 2 kernel: https://ipython.readthedocs.io/en/latest/install/kernel_install.html.
When I run
python2 -m pip install ipykernel
I get back
Could not find a version that satisfies the requirement ipykernel (from versions: )
No matching distribution found for ipykernel.
I am pretty new to using Python (typically use R) and am trying to get the hang of stuff like this, so apologies if the answer here is obvious. I've tried the solutions here to no avail: Jupyter notebook with Python 2 and Python3 Kernel
I have also tried the solutions here: Jupyter Notebook - install python 2. The first solution
$ python2 /path/to/jupyter-notebook
is unclear to me as I don't understand to what file path the code points (for jupyter_notebook). (This is likely a consequence of my noobiness.)
The second,
conda create -n ipykernel_py2 python=2 ipykernel
conda activate ipykernel_py2
python -m ipykernel install --user
triggers the following traceback after the third line:
Traceback (most recent call last):
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/runpy.py", line 163, in _run_module_as_main
mod_name, _Error)
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/runpy.py", line 111, in _get_module_details
__import__(mod_name) # Do not catch exceptions initializing package
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/ipykernel/__init__.py", line 2, in <module>
from .connect import *
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/ipykernel/connect.py", line 13, in <module>
from IPython.core.profiledir import ProfileDir
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/IPython/__init__.py", line 49, in <module>
from .terminal.embed import embed
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/IPython/terminal/embed.py", line 18, in <module>
from IPython.terminal.interactiveshell import TerminalInteractiveShell
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/IPython/terminal/interactiveshell.py", line 16, in <module>
from prompt_toolkit.document import Document
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/prompt_toolkit/__init__.py", line 16, in <module>
from .interface import CommandLineInterface
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/prompt_toolkit/interface.py", line 19, in <module>
from .application import Application, AbortAction
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/prompt_toolkit/application.py", line 3, in <module>
from .buffer import Buffer, AcceptAction
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/prompt_toolkit/buffer.py", line 7, in <module>
from .auto_suggest import AutoSuggest
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/prompt_toolkit/auto_suggest.py", line 13, in <module>
from .filters import to_cli_filter
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/prompt_toolkit/filters/__init__.py", line 33, in <module>
from .base import *
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/prompt_toolkit/filters/base.py", line 5, in <module>
from prompt_toolkit.utils import test_callable_args
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/prompt_toolkit/utils.py", line 9, in <module>
from wcwidth import wcwidth
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/wcwidth/__init__.py", line 12, in <module>
from .wcwidth import ZERO_WIDTH # noqa
File "/opt/anaconda3/envs/ipykernel_py2/lib/python2.7/site-packages/wcwidth/wcwidth.py", line 79, in <module>
from backports.functools_lru_cache import lru_cache
ImportError: No module named functools_lru_cache
Thanks, all.
From version 5.0 ipykernel only runs on Python 3.4+ (from version 5.2 — 3.5+). To install ipykernel` for Python 2.7 you need an older version:
python2 -m pip install 'ipykernel<5.0'
For backports.functools-lru-cache install or force-reinstall it:
pip install -U backports.functools-lru-cache
or
pip install --ignore-installed backports.functools-lru-cache
Related
I'm aware of the -p flag, but whenever I use it to specify an interpreter, the resulting environment can't use pip. I want to use a python 3.x project and a python 2.7 project in the same application - as far as I know, the best way to do that is to install both interpreters with pyenv and make a virtual environment using virtualenv in each project folder, specifying the path to the correct interpreter. Here's what I did:
pyenv install 2.7.18
mkdir my_env
virtualenv -p ~/.pyenv/versions/2.7.18/bin/python my_env
source my_env/bin/activate
pip --version
and here's the output of pip --version (or anything involving pip):
Traceback (most recent call last):
File "/home/imageproc/my_env/bin/pip", line 5, in <module>
from pip._internal.cli.main import main
File "/home/imageproc/my_env/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/imageproc/my_env/lib/python2.7/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/imageproc/my_env/lib/python2.7/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/home/imageproc/my_env/lib/python2.7/site-packages/pip/_internal/cli/cmdoptions.py", line 24, in <module>
from pip._internal.exceptions import CommandError
File "/home/imageproc/my_env/lib/python2.7/site-packages/pip/_internal/exceptions.py", line 10, in <module>
from pip._vendor.six import iteritems
ImportError: No module named six
Similarly, if I do the above with a version of python 3.x installed by pyenv,
Traceback (most recent call last):
File "/home/imageproc/env3810/bin/pip", line 5, in <module>
from pip._internal.cli.main import main
File "/home/imageproc/env3810/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 10, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/imageproc/env3810/lib/python3.8/site-packages/pip/_internal/cli/autocompletion.py", line 9, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/imageproc/env3810/lib/python3.8/site-packages/pip/_internal/cli/main_parser.py", line 7, in <module>
from pip._internal.cli import cmdoptions
File "/home/imageproc/env3810/lib/python3.8/site-packages/pip/_internal/cli/cmdoptions.py", line 24, in <module>
from pip._internal.exceptions import CommandError
File "/home/imageproc/env3810/lib/python3.8/site-packages/pip/_internal/exceptions.py", line 10, in <module>
from pip._vendor.six import iteritems
ModuleNotFoundError: No module named 'pip._vendor.six'
It seems like this output could also be relevant, since a module is missing:
$ python -c "import sys
> for i in sys.path:
> print(i)"
~/my_env
~/.pyenv/versions/2.7.18/lib/python27.zip
~/.pyenv/versions/2.7.18/lib/python2.7
~/.pyenv/versions/2.7.18/lib/python2.7/plat-linux2
~/.pyenv/versions/2.7.18/lib/python2.7/lib-tk
~/.pyenv/versions/2.7.18/lib/python2.7/lib-old
~/.pyenv/versions/2.7.18/lib/python2.7/lib-dynload
~/my_env/lib/python2.7/site-packages
Pip works just fine, of course, when I use virtualenv as normal, e.g.
$ which python
/usr/bin/python
$ mkdir sys_env
$ virtualenv sys_env
$ source sys_env/bin/activate
$ pip --version
pip 20.0.2 from ~/sys_env/lib/python3.8/site-packages/pip (python 3.8)
and with that working, the path is
$ python -c "import sys
> for i in sys.path:
> print(i)"
~/sys_env
/usr/lib/python38.zip
/usr/lib/python3.8
/usr/lib/python3.8/lib-dynload
~/sys_env/lib/python3.8/site-packages
I don't quite know what I'm doing enough to find which part of the path the system python uses is missing for the pyenv-installed python or to figure out why it's missing.
I updated the anaconda Navigator and the Spyder.
But now when I try to launch it, there is the following message:
Traceback (most recent call last):
File "C:\ProgramData\Anaconda3\Scripts\spyder-script.py", line 10, in
sys.exit(main())
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\app\start.py", line 210, in main
from spyder.app import mainwindow
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\app\mainwindow.py", line 119, in
from spyder.utils.environ import WinUserEnvDialog
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\environ.py", line 19, in
from spyder.plugins.variableexplorer.widgets.collectionseditor import (
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\collectionseditor.py", line 57, in
from spyder.plugins.variableexplorer.widgets.collectionsdelegate import (
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\collectionsdelegate.py", line 31, in
from spyder.plugins.variableexplorer.widgets.objectexplorer.attribute_model \
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\objectexplorer\__init__.py", line 23, in
from .objectexplorer import ObjectExplorer
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\variableexplorer\widgets\objectexplorer\objectexplorer.py", line 33, in
from spyder.plugins.editor.widgets.codeeditor import CodeEditor
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\editor\widgets\codeeditor.py", line 70, in
from spyder.plugins.editor.panels import (ClassFunctionDropdown,
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\editor\panels\__init__.py", line 13, in
from .codefolding import FoldingPanel
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\editor\panels\codefolding.py", line 32, in
from spyder.plugins.editor.panels.utils import (
File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\plugins\editor\panels\utils.py", line 15, in
import textdistance
ModuleNotFoundError: No module named 'textdistance'
Can someone please suggest me what should I do
EDIT
I followed what "CanciuCostin" suggested in the comment.
And now I'm getting the following:
I tried conda install -c anaconda qtconsole and conda update qtconsole as well. But still the message is there.. :/
I had the same error today - with the last line about textdistance. I used conda to install text distance from the same environment as spyder and now I can open Spyder again.
conda install textdistance
My anaconda environment uses Python 3.
Well.. I used conda uninstall qtconsole and then once the uninstallation is complete, I installed it again by the command conda install qtconsole. But then I had to install spyder as well ( conda install sypder ).
Then it worked. But I had to install some libraries like scipy ( conda install scipy )
When launching Juypter from Anaconda I receive the following error message:
Traceback (most recent call last):
File "C:\Users\ceo20\Anaconda3\Scripts\jupyter-notebook-script.py", line 6, in
from notebook.notebookapp import main
File "C:\Users\ceo20\Anaconda3\lib\site-packages\notebook\notebookapp.py", line 80, in
from .services.kernels.kernelmanager import MappingKernelManager
File "C:\Users\ceo20\Anaconda3\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 19, in
from jupyter_client.session import Session
File "C:\Users\ceo20\Anaconda3\lib\site-packages\jupyter_client__init__.py", line 4, in
from .connect import *
File "C:\Users\ceo20\Anaconda3\lib\site-packages\jupyter_client\connect.py", line 35, in
from jupyter_core.paths import jupyter_data_dir, jupyter_runtime_dir, secure_write
ImportError: cannot import name 'secure_write' from 'jupyter_core.paths' (C:\Users\ceo20\Anaconda3\lib\site-packages\jupyter_core\paths.py)
Any thoughts?
Try this in Anaconda prompt
pip install --upgrade jupyter_client
pip install --upgrade jupyter_client
This package provides the Python API for starting, managing and communicating with Jupyter kernels. The above code will upgrade jupyter client.
I'm trying to execute ansible in my system. I guess I messed up something and unable to run ansible. When I run ansible --version, I see the following error:
krishnapatamset:bin krishna.patamsetti$ ansible --version
[WARNING]: log file at /var/log/ansible/ansible.log is not writeable and we cannot create it, aborting
ERROR! Unexpected Exception: No module named markupsafe
the full traceback was:
Traceback (most recent call last):
File "/usr/local/bin/ansible", line 80, in <module>
from ansible.cli.adhoc import AdHocCLI as mycli
File "/usr/local/lib/python2.7/site-packages/ansible/cli/adhoc.py", line 28, in <module>
from ansible.executor.task_queue_manager import TaskQueueManager
File "/usr/local/lib/python2.7/site-packages/ansible/executor/task_queue_manager.py", line 29, in <module>
from ansible.executor.play_iterator import PlayIterator
File "/usr/local/lib/python2.7/site-packages/ansible/executor/play_iterator.py", line 30, in <module>
from ansible.playbook.block import Block
File "/usr/local/lib/python2.7/site-packages/ansible/playbook/__init__.py", line 27, in <module>
from ansible.playbook.play import Play
File "/usr/local/lib/python2.7/site-packages/ansible/playbook/play.py", line 27, in <module>
from ansible.playbook.base import Base
File "/usr/local/lib/python2.7/site-packages/ansible/playbook/base.py", line 29, in <module>
from jinja2.exceptions import UndefinedError
File "/usr/local/lib/python2.7/site-packages/jinja2/__init__.py", line 33, in <module>
from jinja2.environment import Environment, Template
File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 13, in <module>
from jinja2 import nodes
File "/usr/local/lib/python2.7/site-packages/jinja2/nodes.py", line 19, in <module>
from jinja2.utils import Markup
File "/usr/local/lib/python2.7/site-packages/jinja2/utils.py", line 531, in <module>
from markupsafe import Markup, escape, soft_unicode
ImportError: No module named markupsafe
Can anyone please help me with this situation. Thanks in advance
I even tried pip install markupsafe but still I am unable to get ansible working
Ansible is based on python and there is a python module that's missing called markupsafe
install it via pip, you may need to escalate privileges
pip2 install -I markupsafe
pip2 for python 2.x
-I to ignore and reinstall package if it's already installed
I uninstalled pip and installed it again.
brew uninstall pip
brew doctor
brew install pip
I did conda install -c acellera pyinstaller=3.2.3 as per Anaconda's website and it looks like it installed correctly but I get the following if I try to run it via cmd:
C:\Users\Cornelis Dirk Haupt\PycharmProjects\Mesoscale-Brain-Explorer\src>pyinstaller
Traceback (most recent call last):
File "C:\Anaconda3\Scripts\pyinstaller-script.py", line 9, in <module>
load_entry_point('PyInstaller==3.3.dev0+g8756735', 'console_scripts', 'pyinstaller')()
File "C:\Anaconda3\lib\site-packages\setuptools-23.0.0-py3.5.egg\pkg_resources\__init__.py", line 542, in load_entry_point
File "C:\Anaconda3\lib\site-packages\setuptools-23.0.0-py3.5.egg\pkg_resources\__init__.py", line 2569, in load_entry_point
File "C:\Anaconda3\lib\site-packages\setuptools-23.0.0-py3.5.egg\pkg_resources\__init__.py", line 2229, in load
File "C:\Anaconda3\lib\site-packages\setuptools-23.0.0-py3.5.egg\pkg_resources\__init__.py", line 2235, in resolve
File "C:\Anaconda3\lib\site-packages\PyInstaller\__main__.py", line 21, in <module>
import PyInstaller.building.build_main
File "C:\Anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 34, in <module>
from .api import PYZ, EXE, COLLECT, MERGE
File "C:\Anaconda3\lib\site-packages\PyInstaller\building\api.py", line 38, in <module>
from PyInstaller.utils.win32 import winmanifest, icon, versioninfo, winresource
File "C:\Anaconda3\lib\site-packages\PyInstaller\utils\win32\versioninfo.py", line 17, in <module>
import pefile
ImportError: No module named 'pefile'
What's going on? Pyinstaller works fine with python 2.7 without Anaconda. But I've recently decided to make the jump to Anaconda + 3.5. I cant find any module named pefile or how to install it with Anaconda. I can install pefile easily using pip3 though.
You can use Anaconda's pip to install it, just go to the Script folder in Anaconda and execute:
pip.exe install pefile
install this instead:
conda install -c conda-forge pyinstaller=3.2.1
working fine for me after a couple of tries!