英文:
`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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论