[英]Why is python importing `scipy` even though I haven't asked it to?
I have a file constants.py
from which I want to import a constant SEED
.我有一个文件constants.py
,我想从中导入一个常量SEED
。
When I run当我跑
from constants import SEED
I get我明白了
ImportError: cannot import name 'SEED' from 'scipy.optimize._highs.constants'
(/opt/conda/envs/rapids/lib/python3.7/site-packages/scipy/optimize/_highs/constants
.cpython-37m-x86_64-linux-gnu.so)
I would understand this if my file was called scipy/optimize/_highs/constants.py
but constants.py
is in my local dir.如果我的文件被称为scipy/optimize/_highs/constants.py
但constants.py
在我的本地目录中,我会理解这一点。
Also, why is python looking several layers deep in scipy?另外,为什么 python 在 scipy 中看起来有好几层? How is it getting from constants import SEED
and from scipuy.optimize._highs.constants import SEED
mixed up?它是如何from constants import SEED
和from scipuy.optimize._highs.constants import SEED
混合起来的?
I am running code on the RAPIDS Paperspace gradient image.我正在 RAPIDS Paperspace 渐变图像上运行代码。
My sys.path
我的sys.path
['/notebooks/TPS-12/analysis', # The dir my notebook + constants.py is in
'/opt/conda/envs/rapids/lib/python37.zip',
'/opt/conda/envs/rapids/lib/python3.7',
'/opt/conda/envs/rapids/lib/python3.7/lib-dynload',
'',
'/opt/conda/envs/rapids/lib/python3.7/site-packages',
'/opt/conda/envs/rapids/lib/python3.7/site-packages/IPython/extensions',
'/root/.ipython']
If you've recently updated your IDE, have you tried to update scipy?如果您最近更新了 IDE,您是否尝试过更新 scipy? I know that's what I had to do when I was using Anaconda.我知道这是我在使用 Anaconda 时必须做的。 Even if you're using a different IDE it's worth a shot.即使您使用不同的 IDE 也值得一试。
Additionally, there might be relevant information here .另外,这里可能有相关信息。 To summarize, try renaming your "constants" module to something else.总而言之,尝试将您的“常量”模块重命名为其他内容。
I was running scipy version 1.6.0 but once I ran conda update scipy
it fixed the problem.我正在运行 scipy 版本 1.6.0 但是一旦我运行conda update scipy
它就解决了问题。
Weirdly enough though that didn't actually update my scipy version.奇怪的是,这实际上并没有更新我的 scipy 版本。 But it installed a bunch of updates and removed some (seemingly unconnected?) libraries like seaborn但它安装了一堆更新并删除了一些(似乎未连接?)库,如 seaborn
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.