Anaconda does not parse conda command - python

It turns out that my Anaconda-Navigator isn't working right so as my Anaconda installation is slightly out of date (4.2.0) I figured I'd start troubleshooting by updating. However, any conda Terminal command (I'm on Mac (Monterey)) gives a massive error, such as:
$ conda list conda
Traceback (most recent call last):
File "~/anaconda/bin/conda", line 4, in <module>
import conda.cli
File "~/anaconda/lib/python2.7/site-packages/conda/cli/__init__.py", line 8, in <module>
from .main import main # NOQA
File "~/anaconda/lib/python2.7/site-packages/conda/cli/main.py", line 46, in <module>
from ..base.context import context
File "~/anaconda/lib/python2.7/site-packages/conda/base/context.py", line 13, in <module>
from .constants import DEFAULT_CHANNELS, DEFAULT_CHANNEL_ALIAS, ROOT_ENV_NAME, SEARCH_PATH, conda
File "~/anaconda/lib/python2.7/site-packages/conda/base/constants.py", line 15, in <module>
from conda._vendor.auxlib.collection import frozendict
File "~/anaconda/lib/python2.7/site-packages/conda/_vendor/auxlib/collection.py", line 6, in <module>
from .compat import text_type
File "~/anaconda/lib/python2.7/site-packages/conda/_vendor/auxlib/compat.py", line 11, in <module>
from ._vendor.five import with_metaclass, WhateverIO as StringIO # NOQA
File "~/anaconda/lib/python2.7/site-packages/conda/_vendor/auxlib/_vendor/five.py", line 80, in <module>
absolute_to_nanoseconds = CoreServices.AbsoluteToNanoseconds
File "~/anaconda/lib/python2.7/ctypes/__init__.py", line 375, in __getattr__
func = self.__getitem__(name)
File "~/anaconda/lib/python2.7/ctypes/__init__.py", line 380, in __getitem__
func = self._FuncPtr((name_or_ordinal, self))
AttributeError: dlsym(RTLD_DEFAULT, AbsoluteToNanoseconds): symbol not found
The only way I could even assess my Anaconda version (as $ conda -V throws something similar) was via
$ python -V
Python 2.7.12 :: Anaconda 4.2.0 (x86_64)
Weirdly, I also get
$ python3 -V
Python 3.7.3
[no Anaconda reference] despite the fact that Anaconda is definitely doing something for Python 2, and Anaconda 4.2.0 comes with Python 3.
Any help with sorting through this would be wonderful.

Related

jupyter notebook python compatibility

I am totally new to Python/Jupyter notebook.
Using Windows 11. I installed latest version python Python 3.11.1. Also latest Anaconda - conda 22.9.0.
My jupyter notebook (installed by anaconda) does not start from command line:
jupyter notebook
Traceback (most recent call last):
File "C:\apps\anaconda\Scripts\jupyter-notebook-script.py", line 6, in from notebook.notebookapp import main
File "C:\apps\anaconda\lib\site-packages\notebook\notebookapp.py", line 77, in from .services.kernels.kernelmanager import MappingKernelManager, AsyncMappingKernelManager
File "C:\apps\anaconda\lib\site-packages\notebook\services\kernels\kernelmanager.py", line 18, in
from jupyter_client.session import Session
File "C:\apps\anaconda\lib\site-packages\jupyter_client_init_.py", line 8, in from .asynchronous import AsyncKernelClient # noqa
File "C:\apps\anaconda\lib\site-packages\jupyter_client\asynchronous_init_.py", line 1, in
from .client import AsyncKernelClient # noqa
File "C:\apps\anaconda\lib\site-packages\jupyter_client\asynchronous\client.py", line 6, in
from jupyter_client.channels import HBChannel
File "C:\apps\anaconda\lib\site-packages\jupyter_client\channels.py", line 12, in import zmq.asyncio
File "C:\apps\anaconda\lib\site-packages\zmq_init_.py", line 103, in from zmq import backend
File "C:\apps\anaconda\lib\site-packages\zmq\backend_init_.py", line 31, in raise original_error from None
File "C:\apps\anaconda\lib\site-packages\zmq\backend_init_.py", line 26, in ns = select_backend(first)
File "C:\apps\anaconda\lib\site-packages\zmq\backend\select.py", line 31, in select_backend mod = import_module(name)
File "C:\apps\anaconda\lib\importlib_init.py", line 127, in import_module return _bootstrap.gcd_import(name[level:], package, level)
File "C:\apps\anaconda\lib\site-packages\zmq\backend\cython_init.py", line 6, in
from . import (ImportError: DLL load failed while importing _device: The specified module could not be found.
Conda documentation states "Anaconda supports Python 3.7, 3.8, 3.9 and 3.10. The current default is Python 3.9."
Should I just downgrade my python to 3.9 or 3.10 (I dont care) ?? Any other work arounds?
Updates
Could open the jupyter notebook from the conda prompt. Not stated using it yet. So lets see. If python compatibility issues need to be resolved - need to figure it out.
But, cant start the anaconda-navigator. When I try start from windows start menu - does nothing. From Conda prompt: I get the flwg error on the prompt: >anaconda-navigator Traceback (most recent call last): File "C:\apps\anaconda\Scripts\anaconda-navigator-script.py", line 6, in <module> from anaconda_navigator.app.main import main File "C:\apps\anaconda\lib\site-packages\anaconda_navigator\app\main.py", line 19, in <module> from anaconda_navigator.app.start import start_app File "C:\apps\anaconda\lib\site-packages\anaconda_navigator\app\start.py", line 15, in <module> from qtpy.QtCore import QCoreApplication, QEvent, QObject, Qt # pylint: disable=no-name-in-module File "C:\apps\anaconda\lib\site-packages\qtpy\QtCore.py", line 15, in <module> from PyQt5.QtCore import * ImportError: DLL load failed while importing QtCore: The specified procedure could not be found.

how to make virtualenv see the default python version on Ubuntu

I encounter an error when creating virtual environment on Ubuntu-16.04.
In particular, virtualenv -p python myenv returns
Traceback (most recent call last):
File "/usr/local/bin/virtualenv", line 7, in <module>
from virtualenv.__main__ import run_with_catch
File "/usr/local/lib/python3.5/dist-packages/virtualenv/__init__.py", line 3, in <module>
from .run import cli_run, session_via_cli
File "/usr/local/lib/python3.5/dist-packages/virtualenv/run/__init__.py", line 7, in <module>
from ..app_data import make_app_data
File "/usr/local/lib/python3.5/dist-packages/virtualenv/app_data/__init__.py", line 9, in <module>
from platformdirs import user_data_dir
File "/usr/local/lib/python3.5/dist-packages/platformdirs/__init__.py", line 29
result: type[PlatformDirsABC] = getattr(importlib.import_module(module), name)
^
SyntaxError: invalid syntax
meaning incorrect syntax in Python 3.5. However, I have set my default python version on Ubuntu to be Python 3.8.9 i.e., python -V returns Python 3.8.9.
So why does virtualenv refer to Python 3.5 even though Python 3.8.9 is default?
Additional info:
My virtualenv version is 15.0.1
The first line in the traceback refers to /usr/local/bin/virtualenv, which looks like this
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import re
import sys
from virtualenv.__main__ import run_with_catch
if __name__ == '__main__':
sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
sys.exit(run_with_catch())
Update:
Running python3 -m pip install virtualenv
returns
Traceback (most recent call last):
File "/usr/lib/python3.8/runpy.py", line 185, in _run_module_as_main
mod_name, mod_spec, code = _get_module_details(mod_name, _Error)
File "/usr/lib/python3.8/runpy.py", line 144, in _get_module_details
return _get_module_details(pkg_main_name, error)
File "/usr/lib/python3.8/runpy.py", line 111, in _get_module_details
__import__(pkg_name)
File "/usr/lib/python3/dist-packages/pip/__init__.py", line 14, in <module>
from pip.utils import get_installed_distributions, get_prog
File "/usr/lib/python3/dist-packages/pip/utils/__init__.py", line 23, in <module>
from pip.locations import (
File "/usr/lib/python3/dist-packages/pip/locations.py", line 9, in <module>
from distutils import sysconfig
ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.8/distutils/__init__.py)
You can use the below command for ensuring that virtualenv refers to python3.8 by default
python3.8 -m virtualenv myenv

How can I use virtualenv to create an environment with an interpreter installed by pyenv?

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.

Cannot install Python 2 kernel in Jupyter Notebook

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

AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'

Im new to programming, so I have met this trouble.
I ve upgraded my pip and then used pip list, ipython notebook, jupyter notebook to use anaconda, so after all this commands I got one answer :
Traceback (most recent call last):
File "/home/bakhytgul/anaconda3/bin/pip", line 7, in <module>
from pip._internal import main
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/pip/_internal/__init__.py", line 40, in <module>
from pip._internal.cli.autocompletion import autocomplete
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/pip/_internal/cli/autocompletion.py", line 8, in <module>
from pip._internal.cli.main_parser import create_main_parser
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/pip/_internal/cli/main_parser.py", line 12, in <module>
from pip._internal.commands import (
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/pip/_internal/commands/__init__.py", line 6, in <module>
from pip._internal.commands.completion import CompletionCommand
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/pip/_internal/commands/completion.py", line 6, in <module>
from pip._internal.cli.base_command import Command
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 19, in <module>
from pip._internal.download import PipSession
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/pip/_internal/download.py", line 15, in <module>
from pip._vendor import requests, six, urllib3
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/pip/_vendor/requests/__init__.py", line 97, in <module>
from pip._vendor.urllib3.contrib import pyopenssl
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/pip/_vendor/urllib3/contrib/pyopenssl.py", line 46, in <module>
import OpenSSL.SSL
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/OpenSSL/__init__.py", line 8, in <module>
from OpenSSL import rand, crypto, SSL
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/OpenSSL/crypto.py", line 13, in <module>
from cryptography.hazmat.primitives.asymmetric import dsa, rsa
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/cryptography/hazmat/primitives/asymmetric/rsa.py", line 14, in <module>
from cryptography.hazmat.backends.interfaces import RSABackend
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/cryptography/hazmat/backends/__init__.py", line 7, in <module>
import pkg_resources
File "/home/bakhytgul/anaconda3/lib/python3.6/site-packages/pkg_resources.py", line 1435, in <module>
register_loader_type(importlib_bootstrap.SourceFileLoader, DefaultProvider)
AttributeError: module 'importlib._bootstrap' has no attribute 'SourceFileLoader'
Can u help me to solve this issue, please? Thank u very much.
Im using:
- Ubuntu 16.04. (64bit)
- Python 2.7.12
- Python 3.6.0 :: Anaconda 4.3.1 (64-bit)
P.S: Ive tried to fix with dotenv, ensurepip(this got me answer that I dont have this package).
Not a full answer because I cannot tell you why this is happening, but hopefully this will help you find a solution.
I had been running into this problem with an venv. When I started from scratch trying to build rjsmin, everything went all right, that is when I noticed that the reason was that the venv that was failing was using Python 3.6, whereas the new venv was using Python 3.7.
According to your console output the anaconda you have is using 3.6, I think you might have break your install by manually upgrading packages using pip. You could try getting the newer version of anaconda, or go with a new, fresh install.

Categories

Resources