首页 > 后端开发 > 正文

如何在ubuntu终端运行python脚本

2024-01-06 04:45:15 | 我爱编程网

小编今天整理了一些如何在ubuntu终端运行python脚本相关内容,希望能够帮到大家。

本文目录一览:

如何在ubuntu终端运行python脚本

ubuntu 下用python写了个生成动态壁纸的脚本,如果通过代码实现使用这个xml,而不是通过桌面->背景->添加

sudo mkdir /usr/share/backgrounds/mybackground-imgs

sudo cd /usr/share/backgrounds/mybackground-imgs

sudo cp /home/你的背景图片所在目录/* .

sudo ./backgroud.py

其中backgroud.py:

#!/usr/bin/env python

#coding=utf-8

import glob, os

import shutil

import time

import Image

filelist=[]

def filelie(path):

if os.path.isfile(path):

wenjian=os.path.splitext(path)[1][1:]

if wenjian=="jpg" or wenjian=="png" or wenjian=="gif":

try:

kuan,gao = Image.open(path).size

if kuan>=1024 and gao>=768:

filelist.append(path)

except IOError:

pass

elif os.path.isdir(path):

for item in os.listdir(path):

itemsrc = os.path.join(path, item)

filelie(itemsrc)

curdir = os.getcwd()

filelie(curdir)

currentImageFiles = filelist

#print filelist

if os.path.isfile('backgroundslide.xml'):

os.remove('backgroundslide.xml')

currentTime = time.localtime()

length = len(currentImageFiles)

f = file('backgroundslide.xml', 'w')我爱编程网

f.write('\n')

f.write('\t\n')

f.write('\t\t' + str(currentTime.tm_year) + '\n')

f.write('\t\t' + str(currentTime.tm_mon) + '\n')

f.write('\t\t' + str(currentTime.tm_mday) + '\n')

f.write('\t\t' + str(currentTime.tm_hour) + '\n')

f.write('\t\t' + str(currentTime.tm_min) + '\n')

f.write('\t\t' + str(currentTime.tm_sec) + '\n')

f.write('\t\n')

f.write('\n')

for i in currentImageFiles:

length = length - 1

f.write('\t\n')

f.write('\t\t550.0\n')

f.write('\t\t' + currentImageFiles[length] +'\n')

f.write('\t\n')

f.write('\t\n')

f.write('\t\t25.0\n')

f.write('\t\t' + currentImageFiles[length] + '\n')

if length >= 1:

f.write('\t\t' + currentImageFiles[length-1] + '\n')

if length <1:

f.write('\t\t' + currentImageFiles[len(currentImageFiles)-1] + '\n')

f.write('\t\n')

f.write('\n')

f.close()

如何在ubuntu终端运行python脚本

如何在ubuntu终端运行python脚本

在ubuntu终端运行python脚本的方法:1、打开终端,查看当前存在的虚拟环境;2、激活需要使用的虚拟环境;3、进入到python脚本所在的目录下;4、执行【python 脚本名】命令即可运行脚本。

具体方法:

(推荐教程:Python入门教程)

1、打开终端,输入'conda env list'命令查看当前存在的虚拟环境(如果没有合适的环境,则需要新建);

2、使用'conda activate pytorch1.0'命令激活将要使用的虚拟环境;

3、使用'cd'命令进入存放demo.py文件的目录下;

4、使用'python'命令运行demo.py文件,同时给部分参数赋值;

参数:

--net vgg16:backbone网络选择vgg16

--cuda:启用gpu

--load_dir models:在models文件夹下加载所需的文件

如何在ubuntu终端运行python脚本

Ubuntu 18.04 中使用python

Ubuntu18.04 系统内自带的Python 是Python3.6。

如果想要安装Python3.7 可以直接使用 sudo apt install python3.7

过程中有问题的话再解决,然后安装对应的pip

安装高版本python 参考

不同的版本对应的pip安装

报错

但是提示pip安装成功,解决办法

使用3.7建立虚拟环境virtualenv

从Python3.3起,Python支持venv . 但是apt install python3.7时并没有自动安装。

需要使用 sudo apt install python3.7-venv将虚拟环境包安装到3.7版本中。 参考

在上述的虚拟环境中 Python 引入模块后VsCode出现问题提示 “could not be resolved” 解决方案

1、在 VsCode 设置中搜索:python.analysis.extraPaths

2、设置路径

以上就是我爱编程网小编为大家带来的内容了,想要了解更多相关信息,请关注我爱编程网。
与“如何在ubuntu终端运行python脚本”相关推荐