[PYTHON] A story about what to do when a bad interpreter: Not such file or directory appears in Anaconda3 and how to investigate the cause.

My environment

macOS Catalina version 10.15.5
conda 4.9.2
anaconda Command line client (version 1.7.2)

Error status

Error message

$ jupyter lab
-bash: /Users/+++/anaconda3/bin/jupyter:
/Users/***/opt/anaconda3/bin/python: bad interpreter:
No such file or directory

I ran Jupyter lab in Anaconda environment for the first time in a while, but I got the above error. This time, I tried to find a solution and the cause. I apologize if I'm wrong!

If you don't know Jupyter lab, you can think of it as Jupyter notebook. Probably there is no big difference between the two in this error. [^ 1]

What I tried

There was a similar article.

There was Article that solved the same error, so I tried that. In this article, it's about a library called html5lib, but in my case Anaconda3 itself was the problem, so I tried another solution. Zubari, I reinstalled Anaconda3.

If you want to know the solution, that's it. Thank you for reading.

I dug a little deeper.

This error message will be displayed again.

Error message

$ jupyter lab
-bash: /Users/+++/anaconda3/bin/jupyter:
/Users/***/opt/anaconda3/bin/python: bad interpreter:
No such file or directory

In the previous article, there was a description that the cause was unknown, so I dug deeper in my own way.

As a result, I did not know the specific cause, so please consider it as an example.

In conclusion, it seems that it was caused by migrating the installed Anaconda3 to another directory. It seems that the directory where Anaconda3 was originally installed was \ Users \ *** \ opt.


As a result, I was getting an error that the python file in the above directory could not be found. [^ 2] However, I was moving from opt for various reasons.


The destination was \ Users \ +++. In order to run jupyter lab, macOS needs to run \ Users \ +++ \ anaconda3 \ bin \ jupyter. [^ 2]

But to run \ Users \ +++ \ anaconda3 \ bin \ jupyter, Make sure the above \ Users \ *** \ opt \ anaconda3 \ bin \ python file is the key. So I opened \ Users \ +++ \ anaconda3 \ bin \ jupyter in my editor. See the first line below.


# -*- coding: utf-8 -*-
import re
import sys

from jupyter_core.command import main

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw?|\.exe)?$', '', sys.argv[0])

Apparently, the Path on the first line and the actual python file are in different locations, causing this error. So, as I wrote in the conclusion, when I originally installed Anaconda3, each library was installed in the directory \ Users \ *** \ opt before the move.

However, by moving the directory of Anaconda3, there was a gap between the Path described in each library and the current directory.

Path at installation


Current Path


While investigating this error, I tried rewriting the jupyter file to the current Path / Users/+++/anaconda3/bin/python. Then jupyter ran properly. [^ 3]

The Article that solved a similar error introduced earlier was solved by this method. But in my case, this didn't help. Be careful with this method. Because many libraries included in Anaconda3 have many dependent libraries.

This means that you need to change the paths of all the libraries needed to run jupyter lab. Unless you have the patience to rewrite all library directories, reinstall Anaconda 3 quietly. ~~ (I just reinstalled it, but maybe it's okay to just go back to the installed directory, but I haven't tried it, so please do it at your own risk) ~~

Error message

$ jupyter lab
-bash: /Users/+++/anaconda3/bin/jupyter:
/Users/***/opt/anaconda3/bin/python: bad interpreter:
No such file or directory

In my case, Anaconda3 is in a directory called \ Users \ +++, so if I moved it to \ Users \ *** \ opt, it should have worked without reinstalling.

Find out for yourself how to reinstall. [^ 4] (If there is demand, I will summarize it at a later date)

that's all. Moving files with a light feeling is fatal. It has become important so far.


At the end, it feels like a throwaway, but before I forget the day again, I summarized it as a memorandum.

As I was writing this article, I noticed that I haven't tried the articles I referred to. Because, in fact, when I saw the Path on the first line, I wanted to try various things by comparing it with the error message. As you are interested, change the environment variable of bash, change the environment variable of direnv [^ 1], and if you are messing with it, write a voluminous article that calls this cause investigation I was able to get such an awareness.

But in the first place, most people probably don't bother to change the directory of the Anaconda3 executable. I've been experimenting with building virtual environments using direnv, so I ran into an error like this. I'm glad I was able to solve it. Honestly, it was fun when the hypothesis was correct.

Ah, I'm using technical terms for this part without any explanation, but if you like things like reading this far, you'll find out for yourself. .. .. Lol

If you have any interest, please see Self-introduction page.

Have a fun engineer life!


Installation of Anaconda3 https://www.anaconda.com/products/individual#Downloads

The following articles are not used in this method, but are for future editing of this article. Please forgive me as an appendix.

Uninstall Anaconda3 https://weblabo.oscasierra.net/python-anaconda-uninstall-macos/

How to set environment variables in Anaconda3 https://timappleblog.com/2019path-anaconda/

[^ 1]: Although not introduced here, it is actually work in a virtual environment managed by direnv. Therefore, since there is a risk different from the actual environment, detailed descriptions such as environment variables are omitted. [^ 2]: The file is written in Python, but when I checked it with the Finder on Mac, it was a Unix executable file, so I am writing it as just a file here. I don't know about the OS. If you are familiar with this, please comment. [^ 3]: When I started learning Python here, I was told that it was magic. Without this error, I thought it would be magical in the future. Other magic, but the magic will be solved as you solve various errors. [^ 4]: Not only the installation of Anaconda3 but also the installation of Python3 has a lot of addictive points in the case of Mac, so it is dangerous to put it together properly without verification, so adding an appendix will make the tea muddy.

Recommended Posts

A story about what to do when a bad interpreter: Not such file or directory appears in Anaconda3 and how to investigate the cause.
What to do when [Errno 2] No such file or directory appears in Python
What to do when the warning "The environment is in consistent ..." appears in the Anaconda environment
What to do if ENOENT: no such file or directory appears during npm install
What to do if you cat or tail a binary file and the terminal is garbled
When I cut the directory for UNIX Socket under / var / run with systemd, I got stuck in a pitfall and what to do
What to do when a warning appears around Python integration in Neovim's CheckHealth
What to do if you get the error RuntimeError: Python is not installed as a framework when trying to use matplitlib and pylab in Python 3.3
What to do when "TypeError: data type not understood" appears in python's numpy.zeros
What to do when the graph does not appear in jupyter (ipython) notebook
What to do if NotADirectoryError: [Errno 20] Not a directory:'xdg-settings' appears in jupyter notebook
How to read a file in a different directory
What to do when is not in the sudoers file.This incident will be reported.
What to do when only the window is displayed and nothing is displayed in pygame Note
What to do when Python starts up in Anaconda does not come out unexpectedly
[Go 1.13] What to do when unexpected directory layout: appears
[openpyxl] What to do when IllegalCharacterError appears in pandas.DataFrame.to_excel
What to do when gdal_merge creates a huge file
When writing to a csv file with python, a story that I made a mistake and did not meet the delivery date
Now in Singapore The story of creating a LineBot and wanting to do a memorable job
How to create a new file when the specified file does not exist — write if the file exists
What to do when a Missing artifact occurs in a jar that is not defined in pom.xml
How to delete "(base)" that appears in the terminal when Anaconda is installed on Mac
A story about porting the code of "Try and understand how Linux works" to Rust
A story about how to specify a relative path in python.
What to do when "SSL: CERTIFICATE_VERIFY_FAILED _ssl.c: 1056" appears in Python
A story about how to deal with the CORS problem
What to do when "Invalid HTTP_HOST header" appears in Django
When I try to run the pip command after updating pip, I get "No such file or directory"
NameError: global name'dot_parser' is not defined and what to do when it comes up in python
[AWS] What to do when the ping command causes a "timeout"
How to give and what the constraints option in scipy.optimize.minimize is
What to do when the jupyterlab extension settings are not reflected
-bash: ./ {file name} .sh: /usr/bin/bash: bad interpreter: No such file or directory
[Introduction to Python] How to use the Boolean operator (and ・ or ・ not)
What to do when the value type is ambiguous in Python?
[Python] What to do when PEP8 is violated in the process of importing from the directory added to sys.path
What to do when "OS Error: [WinError 126] The specified module cannot be found" appears in import torch
[Python] What to do if you get a ModuleNotFoundError when importing pandas using Jupyter Notebook in Anaconda
How to input a character string in Python and output it as it is or in the opposite direction.
[Note] How to deal with unicode error and No such file or directory (output table to excel file with pandas)
[Memorandum] What to do when a warning appears after executing pip list
Replace the directory name and the file name in the directory together with a Linux command.
What to do when the result downloaded via scrapy is in English
How to specify a .ui file in the dialog / widget GUI in PySide
[Docker] What to do when error Couldn't find the binary git appears
The file name was bad in Python and I was addicted to import
What to do when a warning message is displayed in pip list
When bus = smbus.SMBus (1) gets IOError: [Errno 2] No such file or directory when trying to start the GrovePi starter kit
How to save the feature point information of an image in a file and use it for matching
A command to specify a file with a specific name in a directory with find and mv, cp, or gzip it (linux)
In pandas.DataFrame, even when assigning only a specific column, if index is attached, you do not have to worry about the order of data
How to use Anaconda interpreter in PyCharm
Example of what to do when the sample script does not work (OpenCV-Python)
What to do when "TypeError: must be string, not int…" appears when using strptime
How to count the number of elements in Django and output to a template
What to do when xlrd.biffh.XLRDError: Unsupported format, or corrupt file: Expected BOF record;
How to read a serial number file in a loop, process it, and graph it
What to do if a version error occurs in the selenium Chrome driver
[EC2] What to do when selenium is stuck and processing does not proceed
What do you like about how to convert an array (list) to a string?