我在 Crunchbang 上使用virtualenv, virtualenvwrapper, zsh, oh-my-zsh, 终止符。
我正在尝试virtualenv像这样显示当前的名称
workon example
(example)...
Run Code Online (Sandbox Code Playgroud)
我尝试了很多解决方案,但似乎都不起作用,这是我的 .zshrc文件,我知道修复它没什么大不了的,但我找不到正确的解决方案。自从上次使用Linux进行Django开发已经很久了,我忘记了我曾经做过的事情。
现在,我明白了username@crunchbang,我不知道我使用的是哪个 virtualenv。
我相信这应该很简单,但我无法让它正常工作。
这些是我可以在命令行上运行的命令:
cd /home/debian/ap
# Start a virtualenv
source venv-ap/bin/activate
# This needs to happen inside the virtualenv and takes ~20 seconds
crossbar start
# Outside the virtualenv, perhaps in a different command line window
python3 /home/debian/myscript.py
Run Code Online (Sandbox Code Playgroud)
这些命令必须按此顺序执行。由于 virtualenv、不可执行的 crossbar 以及之后的单独 python 脚本,我一直无法找出使其工作的最佳方法。我目前正在进行的工作:
[Unit]
Description=Start CB
After=network.target
[Service]
Type=simple
User=debian
ExecStartPre=source /home/debian/ap/venv-ap/bin/activate
ExecStart=cd /home/debian/ap/ && crossbar start
Restart=always
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud) 我有一台安装了 Python 2.6 作为默认 Python 的机器。然后,我安装了 Python 2.7,并手动创建了 /usr/bin/python 作为新安装的符号链接。
然后,我遇到了 command-not-found 的问题。我正在尝试重新安装它:
sudo apt-get remove command-not-found
Run Code Online (Sandbox Code Playgroud)
我收到这个错误:
/usr/bin/python does not match the
python default version. It must be
reset to point to python2.6
Run Code Online (Sandbox Code Playgroud)
但我真的希望 Python 2.7 成为默认值。我该如何解决这个烂摊子?
是否可以在 ChromeOS 机器上运行 Python 解释器?我找到了您可以使用的各种编辑器,但我也希望能够运行 Python 应用程序。
我想购买三星 Chromebook,作为一名计算机科学专业的学生,我希望能够在它上面完成我的 CS 作业,而不是随身携带我的 15 英寸 Macbook 或东芝。
我为 Python 脚本创建了一个新服务,该服务在独立运行时有效,但在通过 systemd 运行时出现以下错误:
Oct 02 12:17:09 raspberrypi systemd[1]: Started Read pressure And Post to mqtt.
Oct 02 12:17:09 raspberrypi systemd[1]: ReadPressure.service: Main process exited, code=exited, status=203/EXEC
Oct 02 12:17:09 raspberrypi systemd[1]: ReadPressure.service: Unit entered failed state.
Oct 02 12:17:09 raspberrypi systemd[1]: ReadPressure.service: Failed with result 'exit-code'.
Oct 02 12:17:09 raspberrypi systemd[1]: ReadPressure.service: Service hold-off time over, scheduling restart.
Oct 02 12:17:09 raspberrypi systemd[1]: Stopped Read pressure And Post to mqtt.
Oct 02 12:17:09 raspberrypi systemd[1]: ReadPressure.service: Start request …Run Code Online (Sandbox Code Playgroud) 我即将在 VPS 上的 Ubuntu 上运行一个 python 脚本。这是机器学习培训过程,因此需要花费大量时间进行培训。如何在不停止该过程的情况下关闭腻子。
我有一个 bash 脚本,它启动一个 python3 脚本(让我们称之为startup.sh),关键行:
nohup python3 -u <script> &
Run Code Online (Sandbox Code Playgroud)
当我ssh直接进入并调用此脚本时,python脚本在我退出后继续在后台运行。但是,当我运行此命令时:
ssh -i <keyfile> -o StrictHostKeyChecking=no <user>@<hostname> "./startup.sh"
Run Code Online (Sandbox Code Playgroud)
该过程ssh在完成运行后立即结束并关闭会话。
两者有什么区别?
编辑:python 脚本通过 Bottle 运行 Web 服务。
EDIT2:我也尝试创建一个调用startup.sh和运行的初始化脚本ssh -i <keyfile> -o StrictHostKeyChecking=no <user>@<hostname> "sudo service start <servicename>",但得到了相同的行为。
EDIT3:也许是脚本中的其他内容。这是脚本的大部分内容:
chmod 700 ${key_loc}
echo "INFO: Syncing files."
rsync -azP -e "ssh -i ${key_loc} -o StrictHostKeyChecking=no" ${source_client_loc} ${remote_user}@${remote_hostname}:${destination_client_loc}
echo "INFO: Running startup script."
ssh -i ${key_loc} -o StrictHostKeyChecking=no ${remote_user}@${remote_hostname} "cd ${destination_client_loc}; …Run Code Online (Sandbox Code Playgroud) 我编写了以下脚本来测试 Python 排序功能的速度:
from sys import stdin, stdout
lines = list(stdin)
lines.sort()
stdout.writelines(lines)
Run Code Online (Sandbox Code Playgroud)
然后,我将其与sort包含 1000 万行的文件上的 coreutils命令进行了比较:
$ time python sort.py <numbers.txt >s1.txt
real 0m16.707s
user 0m16.288s
sys 0m0.420s
$ time sort <numbers.txt >s2.txt
real 0m45.141s
user 2m28.304s
sys 0m0.380s
Run Code Online (Sandbox Code Playgroud)
内置命令使用了所有四个 CPU(Python 只使用了一个),但运行时间大约是其 3 倍!是什么赋予了?
我使用的是 Ubuntu 12.04.5(32 位)、Python 2.7.3 和sort8.13
我必须使用 shell 脚本对以下列表进行排序,并使最新版本出现在底部或顶部。我将如何仅使用 shell 工具来做到这一点?
release-5.0.0.rc1
release-5.0.0.rc2
release-5.0.0
release-5.0.1
release-5.0.10
release-5.0.11
release-5.0.13
release-5.0.14
release-5.0.15
release-5.0.16
release-5.0.17
release-5.0.18
release-5.0.19
release-5.0.2
release-5.0.20
release-5.0.21
release-5.0.22
release-5.0.23
release-5.0.24
release-5.0.25
release-5.0.26
release-5.0.27
release-5.0.28
release-5.0.29
release-5.0.3
Run Code Online (Sandbox Code Playgroud) 如果我尝试在 bash 脚本中启动 python,脚本将停止运行并且在调用“Python”后不会执行任何命令。在这个简单的例子中,不会打印“TESTPRINT”。似乎脚本刚刚停止。
#!/bin/bash
python
print("TESTPRINT")
Echo
Run Code Online (Sandbox Code Playgroud)
进入Python后如何让脚本继续运行?我相信几年前我在编写了一个首先需要外壳到 Android 手机的脚本后遇到了同样的问题。我不记得当时我是如何修复它的。