[PYTHON] Anaconda3 × Pycharm environment construction memo
Python de amateur built the environment with Anaconda3 and Pycharm.
I will leave it as a memorandum.
◆ Environment
- OS:Windows 10 Enterprise
--OS version: 1809
--OS build: 17763.1518
--Python version: 3.8 (Anaconda3)
- IDE:Pycharm Community(2020.2.3)
◆ Flow of environment construction
First, install Anaconda and Pycharm Community.
Conducted by referring to the here page.
Execution is completed up to Hello World without any trouble.
- At first, I installed Anaconda and Pycharm while looking at various pages such as Python official, but for some reason openpyxl could not be imported. By the way, the error is as follows.
python
ModuleNotFoundError: No module named 'openpyxl'
In the execution environment, openpyxl is already installed, and if you import openpyxl from the command prompt, you can execute it without any problem.
・ Cause
In the execution environment used in Pycharm (strictly speaking, an Excel processing project created on Pycharm), openpyxl was not installed (in Pycharm (or Python?), Each project has a virtual execution environment individually. You can have it. You can reuse one virtual execution environment).
・ Countermeasures
Solved by creating a virtual environment with Anaconda Navigator and installing openpyxl there.
・ Countermeasures (detailed procedure)
- Launch Anaconda Navigator
- Click Create ("+" button)
- Select NaturalLanguage01 for "Name" and Python3.8 for "Packages" and click "Create"
- Select "All" in the drop-down list and enter "anaconda" in the search box
- Check "anaconda" and click "apply"
It looks like it should be a countermeasure ... w
The above procedure creates a virtual execution environment for Anaconda with "openpyxl" installed (as a result). You will need the path of the virtual execution environment created here later.
- In this case, "C: \ users \ username \ Anaconda3 \ envs \ NaturalLanguage01 \ python.exe"
Next, in Pycharm, add an interpreter that specifies this execution environment.
- Start Pycharm and open "File"-> "Settings"-> any project (this time "Project: sampleOpenPyExcel")-> "Python Interpreter"
- Click the gear icon at the top right of the screen → "Add"
- Click "System Interpreter" → Click "..." at the top right of the screen
- Find and select "Python.exe" directly under the virtual execution environment created by Anaconda, and click "OK".
- Close the "Settings" window and click "run" → "Edit Configrations"
- Select the program file to which you want to apply the environment, select "Environment"-> "Python Interpreter", select the virtual execution environment you added earlier, and click "OK".
This completes the settings.
It was also possible to import the library.