macOS Catalina version 10.15.5
Python3.8.5
Anaconda3
conda 4.9.2
anaconda Command line client (version 1.7.2)
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]
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.
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
.
/Users/***/opt/anaconda3/bin/python:
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.
/Users/+++/anaconda3/bin/jupyter:
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.
#!/Users/***/opt/anaconda3/bin/python
# -*- 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])
sys.exit(main())
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
/Users/***/opt/anaconda3/bin/python:
Current Path
/Users/+++/anaconda3/bin/jupyter:
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