如何解决setup.py文件不存在错误并在Python IDLE中安装folium模块
Hey there! Let's work through your problems one by one.
First: Why you're getting the setup.py error
The command python setup.py install only works if you're in a directory that actually has a setup.py file—this is used for installing Python packages from their raw source code. Since you don't have that file in your current terminal directory, you're seeing that "No such file or directory" error.
Unless you specifically need to install folium from its source code, you don't need to use this command at all. Your existing attempts with pip/conda are the right approach—we just need to make sure that installation is accessible to IDLE.
Getting Folium to Work in IDLE
The issue here is that PyCharm and IDLE are probably using different Python environments. Here's how to fix that:
Find out which Python interpreter IDLE is using
- Open IDLE, and check the top of the shell window—it'll show something like
Python 3.10.12 (main, Jun 11 2024, 05:26:28) [GCC 11.4.0] on linux - For a precise path, run this in the IDLE shell:
This will output the full path to the Python executable IDLE is using (likeimport sys print(sys.executable)/home/yourname/miniconda3/bin/pythonor/usr/bin/python3.10).
- Open IDLE, and check the top of the shell window—it'll show something like
Install folium directly for that interpreter
- Open your terminal, and use that path to run pip. For example, if the path was
/usr/bin/python3.10, run:/usr/bin/python3.10 -m pip install folium - If you're using a conda environment:
- First activate the environment in your terminal (e.g.,
conda activate your_env_name) - Then run
pip install folium - After that, open IDLE from the same terminal session (just type
idleand hit enter)—this will launch IDLE using the activated conda environment.
- First activate the environment in your terminal (e.g.,
- Open your terminal, and use that path to run pip. For example, if the path was
Verify the installation
Open IDLE again and runimport folium. If you don't get any error messages, you're all set!
If you do want to install from source (optional)
If you need to use setup.py install for some reason, follow these steps:
- Download the folium source code (as a ZIP file from the project's repository)
- Unzip the file to a folder on your computer
- Open your terminal, navigate to that unzipped folder (use
cd /path/to/unzipped/folium-folder) - Now run
python setup.py install—this will work because the folder contains the requiredsetup.pyfile.
内容的提问来源于stack exchange,提问作者Andrews

