0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Python_moduleをimportできるパスを確認、追加する

Posted at

moduleをimportできるパスを確認する

import sys

print(sys.path)

['/opt/conda/lib/python37.zip', '/opt/conda/lib/python3.7', '/opt/conda/lib/python3.7/lib-dynload', '', '/opt/conda/lib/python3.7/site-packages', '/opt/conda/lib/python3.7/site-packages/IPython/extensions', '/home/jovyan/.ipython']

moduleを使えるようにするために、パスを追加する

sys.append('path')で追加できる。
一階層上のディレクトリのpathの追加は以下のように書ける。
~/.bashrcにPYTHONPATHを追加する方法もあるが、それは恒久的に使いたい場合に用いる。

import os
import sys

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

importしたmoduleがどこのパスにあるのか確認する

sys.pathで確認したパスのどこにnumpyが入っていたかわかる。

import sys
import numpy as np

print(np.__file__)

/opt/conda/lib/python3.7/site-packages/numpy/init.py

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?