Pycharm:import文で「Unresolved reference」と警告されてしまう
/hoge/app1/ /hoge/app2/child1/ __ini__.py hoge.py fuga.py /hoge/app2/child2/
というフォルダ構成で、app1とapp2はDjangoフレームワーク上で別アプリとして開発している。
この状態でhoge.pyでfuga.pyをimportするときは
from child1.fuga import ~~
と記述しなければいけないのですが、普通にPycharmで記述していると「Unresolved reference~~」とWarningがでます。
その場合の対処方法
app2フォルダで右クリックをして「Mark Directory As」→「Source Root」を選択する。
Pythonの作法がよくわかってなくて詰まってたけど、なんとか解決してよかった。
参考にしたサイトはこちら↓
python - Unresolved reference issue in PyCharm - Stack Overflow
大文字小文字のディスクイメージを作った際にIntelliJ系のツールを立ち上げるとエラーが出る。
Macで大文字小文字に区別するディスクイメージを作ったときに発生した現象。
どうも大文字小文字の区別をつけたことによって、AndroidStudioとかPycharmを起動した時に警告がでるので
vi ~/Library/Preferences/<appFolder>/idea.properties
として
idea.case.sensitive.fs=true
を追記して再起動。
詳しくはこちら
Filesystem Case-Sensitivity Mismatch - IntelliJ IDEA - Confluence
Vagrantでエラーが出て起動できない。
Failed to mount folders in Linux guest. This is usually because the "vboxsf" file system is not available. Please verify that the guest additions are properly installed in the guest and can work properly. The command attempted was: mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant The error output from the last command was: /sbin/mount.vboxsf: mounting failed with the error: No such device
こんなエラーが出るので
vagrant plugin install vagrant-vbguest vagrant reload
このように入力して対応したらうまくいきましたとさ。
WindowsにDjangoの開発環境を作ってみる その2
とりあえずPostgreSQLが動くようになったので、次はDjangoからPostgreSQLに接続する。
と
Settings | Django documentation | Django
を参考にしながらsettings.pyを修正。
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'mydatabase', 'USER': '{ユーザー名}', 'PASSWORD': '{パスワード}', 'HOST': '{ホスト}', 'PORT': '5432', } }
そして、マイグレーションを実行
python manage.py migrate
すると
django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named 'psycopg2'
こんな感じのエラーが。もう嫌な予感しかしない。
色々と調べてるとこちらの情報に行き着いた。qiita.com
とりあえず
pip3.4 install psycopg2
を実行すると
Command python setup.py egg_info failed with error code・・・
という感じでインストールできない/(^o^)\
そもそも最終的には
ubuntuのPythonからubuntuのポスグレに繋げるのに、開発環境ではWindowsという環境の差が厳しいのかもしれない/(^o^)\
DockerでPostgreSQL環境を作る その3
前回色々ごちゃごちゃやってたらよくわかんなくなってきたので、とりあえず、実務では絶対やってはいけないパターンでPostgreSQLの実行環境を作りました。
1.Dockerのコンテナの作成。
コンテナの/appという場所を諸々のデータ置き場として利用する。
docker run -i -t --name postgresql -v {ホスト側のパス}:/app -p 127.0.0.1:5432:5432 postgresql/ubuntu:1.0 /bin/bash
2.シェルスクリプトの作成
シェルスクリプトの中で
/usr/lib/postgresql/9.3/bin/postgres
を直接叩いて、データディレクトリの場所やコンフィグの場所を指定する。
コンフィグファイルは/app/の下に作ってあげます。
(ホスト側と共有します)
とりあえず、これで起動したからよしとします。
DockerでPostgreSQL環境を作る その2 結論から言うとまだ出来上がってない/(^o^)\
前回はひとまずDocker(ubuntu)でポスグレが動いたのですが、運用していくにはちょっと面倒くさい状況なので、少しずつ改善しようとしています。
プロセスの管理を楽にしようと思い、まずはsupervisorを入れてみる。
前回入れたsysv-rc-confを使わない理由は、postgresqlの起動スクリプトがけっこう色々と細かく書かれていたので、もっとシンプルに必要な機能だけを管理したかったから。
たとえば、今回はpostgresqlのデータファイルの場所とか設定ファイルの場所をDockerのホストファイルと共有するディレクトリに作って管理したい。
その場合postmasterプロセスの起動時にオプションでそれらを設定すればいい。
supervisorを使うと、その起動時のオプションを手軽に変えつつ、プロセスの管理もやってくれそうな感じがした(゚д゚)
apt-getでも入るみたいだけどpipで入れてみます。
まずはpipのインストール
# apt-get install curl curl -kL https://raw.github.com/pypa/pip/master/contrib/get-pip.py | python3.4
pip経由でsupervisorを入れてみると・・・
pip3.4 install supervisor Collecting supervisor Downloading supervisor-3.1.3.tar.gz (391kB) 100% |################################| 393kB 132kB/s Complete output from command python setup.py egg_info: Supervisor requires Python 2.4 or later but does not work on any version of Python 3. You are using version 3.4.0 (default, Apr 11 2014, 13:05:11) [GCC 4.8.2]. Please install using a supported version. ---------------------------------------- Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ym1nkw4r/supervisor
あっれぇ・・・。
Python3だと入らない??
# pip install supervisor Collecting supervisor Using cached supervisor-3.1.3.tar.gz Requirement already satisfied (use --upgrade to upgrade): meld3>=0.6.5 in /usr/lib/python2.7/dist-packages (from supervisor) Building wheels for collected packages: supervisor Running setup.py bdist_wheel for supervisor Stored in directory: /root/.cache/pip/wheels/79/0a/78/0f4e718db0adccf4e5423de0e0f5dcc2c3bc5e4d73ca2cd471 Successfully built supervisor Installing collected packages: supervisor Successfully installed supervisor-3.1.3
はいった・・・(゚д゚)
ポスグレ用のsupervisorの設定ファイルを書いてみる
# vi /etc/supervisor/conf.d/postgresql.conf
[program:postgresql] command=/usr/bin/pg_ctlcluster 9.3 main start ; user=postgres ; autorestart=true stdout_logfile=/var/log/supervisor/jobs/GrowthForecast-supervisord.log ; stdout_logfile_maxbytes=1MB stdout_logfile_backups=5 stdout_capture_maxbytes=1MB redirect_stderr=true ; ~
今回久々にポスグレを触ったのだけど、昔触ったのとなんか違う。
というか調べてみたらubuntuはちょっと仕組みが違うんですって。
pg_ctl経由でサーバーを起動するのではなくてpg_ctlcluster経由で管理するみたい。
引数の9.3はバージョン指定。
これがあるから、異なるバージョンのポスグレが簡単に共存できるとか。
(間違ってたらごめんなさい)
ポスグレ用の設定ファイル作ったので起動してみる。
# cd /etc/supervisor # supervisord /usr/local/lib/python2.7/dist-packages/supervisor/options.py:296: UserWarning: Supervisord is running as root and it is searching for its configuration file in default locations (including its current working directory); you probably want to specify a "-c" argument specifying an absolute path to a configuration file for improved security. 'Supervisord is running as root and it is searching ' Error: The directory named as part of the path /var/log/supervisor/supervisord.log does not exist.
ぬぅ・・・・
とりあえず、エラーが出ているログファイルを作ってみる
# mkdir /var/log/supervisor;chmod 777 /var/log/supervisor # touch /var/log/supervisor/supervisord.log;chmod 777 /var/log/supervisor/supervisord.log
南無三・・・
# supervisorctl status
bash: /usr/bin/supervisorctl: No such file or directory
オワタ・・・/(^o^)\
色々と試行錯誤しながらしたせいで環境が汚くなったのかしら。。存在しないファイルにパスが通ってる・・・
とりあえず、もっかいコンテナから作りなおそうかな。
こういう時にDockerって便利ですね。