Python 用PyCharm调试。先运行脚本
我正在尝试使用PyCharm调试我的测试,但我当前遇到以下错误:Python 用PyCharm调试。先运行脚本,python,bash,pycharm,Python,Bash,Pycharm,我正在尝试使用PyCharm调试我的测试,但我当前遇到以下错误: pydev debugger: process 2386 is connecting Traceback (most recent call last): File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2222, in <module> globals = debugger.run(setup['file']
pydev debugger: process 2386 is connecting
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 2222, in <module>
globals = debugger.run(setup['file'], None, None)
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1648, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Applications/PyCharm.app/Contents/helpers/pycharm/utrunner.py", line 116, in <module>
modules = [loadSource(a[0])]
File "/Applications/PyCharm.app/Contents/helpers/pycharm/utrunner.py", line 40, in loadSource
module = imp.load_source(moduleName, fileName)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/imp.py", line 171, in load_source
module = methods.load()
File "<frozen importlib._bootstrap>", line 1220, in load
File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
File "<frozen importlib._bootstrap>", line 1129, in _exec
File "<frozen importlib._bootstrap>", line 1471, in exec_module
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "/Users/bli1/Development/Trinity/qa-trinity/python_lib/qe/tests/test_web_events.py", line 21, in <module>
import qe.util.scratchstore as scratchstore
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_pluginbase.py", line 452, in plugin_import
fromlist, level)
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_pluginbase.py", line 452, in plugin_import
fromlist, level)
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_pluginbase.py", line 452, in plugin_import
fromlist, level)
ImportError: No module named 'qe'
setup.sh的内容:
#!/bin/bash
[[ $_ != $0 ]] && this_is_sourced=1 || this_is_sourced=""
this_script_path="${BASH_SOURCE[@]}"
if [[ ${this_is_sourced} ]]; then
pushd $(dirname ${this_script_path}) >/dev/null
this_script_dir=$(pwd)
this_script_pkgs=$(echo qe/[a-z]*[a-z0-9] | sed 's%qe/%%g')
popd >/dev/null
#### set environment vars
export PYTHONPATH="$this_script_dir"
export PYTHONDONTWRITEBYTECODE="1"
/usr/bin/env | grep -Fe "PYTHON" >/dev/tty
export PATH="/trinityqa00/opt/bin:/qa00/opt/bin:/home/sthe/opt/bin:${PATH}"
for pkg in $this_script_pkgs; do
export PATH="${PYTHONPATH}/qe/${pkg}:${PATH}"
done
echo "PATH=${PATH}" >/dev/tty
####
unset this_script_dir
unset this_script_path
unset this_is_sourced
else
echo "usage: source ${this_script_path}"
exit
fi
在您的运行配置中,有一个“启动前”部分,您可以在其中添加要在程序启动前运行的任务-我不确定这是否与脚本在相同的环境中运行,但似乎很可能-可能值得一试。感谢您的帮助!我不知道为什么。在启动之前,我将脚本添加到了
。我得到了/Users/bli1/Development/Trinity/qa Trinity/python_lib/setup.sh/Users/bli1/Development/Trinity/qa Trinity/python_lib/setup.sh:line 12:/dev/tty:Device not configured/Users/bli1/Development/Trinity/qa Trinity/python_lib/setup.sh:line 17:/dev/tty:Device not configured
不确定这意味着什么。这个脚本不是我的。我现在正在复制一个proj,听起来像是在寻找一个交互式终端,而Pycharm没有给它(大概是Pycharm的一个管道)。恐怕我不知道该怎么办。@Lattyware谢谢您的尝试!我真的很感激!qe模块实际位于何处?就我所见,source.sh主要向PATH添加目录,这不应该影响Python导入。
#!/bin/bash
[[ $_ != $0 ]] && this_is_sourced=1 || this_is_sourced=""
this_script_path="${BASH_SOURCE[@]}"
if [[ ${this_is_sourced} ]]; then
pushd $(dirname ${this_script_path}) >/dev/null
this_script_dir=$(pwd)
this_script_pkgs=$(echo qe/[a-z]*[a-z0-9] | sed 's%qe/%%g')
popd >/dev/null
#### set environment vars
export PYTHONPATH="$this_script_dir"
export PYTHONDONTWRITEBYTECODE="1"
/usr/bin/env | grep -Fe "PYTHON" >/dev/tty
export PATH="/trinityqa00/opt/bin:/qa00/opt/bin:/home/sthe/opt/bin:${PATH}"
for pkg in $this_script_pkgs; do
export PATH="${PYTHONPATH}/qe/${pkg}:${PATH}"
done
echo "PATH=${PATH}" >/dev/tty
####
unset this_script_dir
unset this_script_path
unset this_is_sourced
else
echo "usage: source ${this_script_path}"
exit
fi