`conda info -a`没有显示我要添加的路径

huangapple go评论77阅读模式
英文:

`conda info -a` not showing the PATH I am trying to add

问题

I am working inside a Conda environment and trying to add a location to PATH.

The reason is that I want to import a script in the parent directory of the script being run.

Directory I am working in: C:/Users/.../gompertz_forecasting

Directory of script (being run): c:/Users/.../gompertz_forecasting/src/pre_processing/pre_processing_factors.py

Directory of script imported: c:/Users/.../gompertz_forecasting/src/staging/generate_factors.py

I am importing using the command from src.staging.generate_factors import x,y,z

However, I keep getting the message "ModuleNotFoundError: No module named 'src'" even though I have added the directory to both the Path and PYTHONPATH via the Windows System Properties.

So, while the path has been added, I still cannot import the module.

When I print conda info -a the added path fails to show up as part of PATH, which is what I believe the issue is.

Expected solution is to simply run conda develop C:\Users\...\gompertz_forecasting\src but this does not add the directory to the PATH. It is still missing when running conda info -a again.

英文:

I am working inside a Conda environment and trying to add a location to PATH.

The reason is that I want to import a script in the parent directory of the script being run.

Directory I am working in:
C:/Users/.../gompertz_forecasting

Directory of script (being run):
c:/Users/.../gompertz_forecasting/src/pre_processing/pre_processing_factors.py

Directory of script imported:
c:/Users/.../gompertz_forecasting/src/staging/generate_factors.py

I am importing using the command
from src.staging.generate_factors import x,y,z

However, I keep getting the message "ModuleNotFoundError: No module named 'src'"
even though I have added the directory to both the Path and PYTHONPATH via the Windows System Properties.

So, while the path has been added, I still cannot import the module.
When I print conda info -a the added path fails to show up as part of PATH, which is what I believe the issue is.

Expected solution is to simply run
conda develop C:\Users\...\gompertz_forecasting\src but this does not add the directory to the PATH. It is still missing when running conda info -a again.

答案1

得分: 0

如果您在conda环境中,请确保从相同的环境中运行conda develop。如果仍然不起作用,让我们尝试在导入模块之前从Python内部手动添加路径到您的PYTHONPATH

import sys
sys.path.append(r"C:\Users\...\gompertz_forecasting\src")

from staging.generate_factors import x, y, z
英文:

If you are inside conda environment make sure to run conda develop from within the same environment. If it still dont work lets try to manually add the path to your PYTHONPATH from within Python before you import the module.

import sys
sys.path.append(r"C:\Users\...\gompertz_forecasting\src")

from staging.generate_factors import x, y, z

huangapple
  • 本文由 发表于 2023年6月12日 04:08:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76452334.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定