为何出现ImportError: No module named visual.graph错误?已装VPython仍报错
ImportError: No module named visual.graph & Conda UnsatisfiableError with VPython Hey there, let's break down and fix your VPython issues one by one:
1. The Root Import Issue: VPython's Module Name Changed
First off, the old visual module is deprecated in newer VPython versions—they've switched to using vpython as the main package name. That's why your from visual.graph import * line is throwing an error, even if you thought you installed VPython correctly.
Fix your code import first:
Replace:
from visual.graph import *
With:
from vpython.graph import *
2. Resolving the Conda UnsatisfiableError (Astropy + VPython Conflict)
The conflict between astropy and vpython in your base environment is a common conda dependency issue. Here are two reliable fixes:
Option 1: Create a Fresh Conda Environment (Recommended)
Isolating VPython in its own environment avoids messing with your base setup's existing packages:
- Create a new environment (name it whatever you like, e.g.,
vpython-env):conda create -n vpython-env python=3.9 - Activate the environment:
conda activate vpython-env - Install VPython in this clean environment:
conda install -c mwcraig vpython
Option 2: Install VPython via Pip
If you want to stick with your base environment, pip is less strict about dependency conflicts than conda:
pip install vpython
3. Verify the Fix
After installing correctly, test with a simple graph snippet to make sure everything works:
from vpython.graph import * # Create a simple plot graph(title='Test Graph', xtitle='X', ytitle='Y') f1 = gcurve(color=color.blue) for x in range(10): f1.plot(x, x**2)
If this runs without errors, you're all set!
内容的提问来源于stack exchange,提问作者Vitor Bento

