1
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 1 year has passed since last update.

ModuleNotFoundError: No module named 'encodings'が止まらない

Posted at

色々やったら以下のエラーが止まらない

ModuleNotFoundError: No module named 'encodings'

対象

Conoha VPSでDjango + Apache + WSGI + pyenv +Python venvでWeb開発をしている。

Conoha VPSは最初はシステムpythonを使う状態のテンプレートを提供しているのだが、これをpyenvを用いたpythonの仮想環境にしようとした。

結論

今回の原因は、rootからpyenvを使ってpython環境を構築したことだった

実は、お恥ずかしいことにあまり把握していなかったのだが、インストールしたパッケージは作成したvenv/lib/python3.X/site-packagesに保存されるが、pythonにもとから入っているencodingsなどは、元の/root/.pyenv/versions/3.9.0の中にある

試すとわかる

Python 3.9.0 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import encodings
>>> encodings.__file__
'/root/.pyenv/versions/3.9.0/lib/python3.9/encodings/__init__.py'                                   >>>

そのため、このrootディレクトリにあるencodingsはapacheには読み込めないという感じ。

ユーザーアカウントでpyenvをinstallして、仮想環境を作成したら上手くいった

1
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
1
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?