python如何下載指定版本TensorFlow
一、python安裝與下載依賴
依賴版本
TensorFlow>=2.3.0 Keras >= 2.4.3 Numpy < 1.19.0 Pandas >= 1.1.0 scikit-learn >= 0.23.2 librosa >=0.8.0 scipy==1.4.1
依賴下載
TensorFlow>=2.3.0 pip3 install tensorflow-cpu==2.3.0 -i https://pypi.douban.com/simple/ Keras >= 2.4.3 pip3 install Keras==2.4.3 -i https://pypi.douban.com/simple/ Pandas >= 1.1.0 pip3 install Pandas==1.1.0 -i https://pypi.douban.com/simple/ scikit-learn >= 0.23.2 pip3 install scikit-learn==0.23.2 -i https://pypi.douban.com/simple/ librosa >=1.19.1 pip3 install librosa==0.8.0 -i https://pypi.douban.com/simple/ scipy==1.4.1 pip3 install scipy==1.4.1 -i https://pypi.douban.com/simple/
安裝python3
yum -y install gcc yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tgz tar -zxvf Python-3.7.3.tgz mkdir /usr/local/python3 cd Python-3.7.3 ./configure --prefix=/usr/local/python3 make && make install ln -sf /usr/local/python3/bin/python3.7 /usr/bin/python3 ln -sf /usr/local/python3/bin/pip3.7 /usr/bin/pip3
驗(yàn)證
pip3 list
pip3升級(jí)
pip3 --default-timeout=10000 install -U pip
pip3 卸載與安裝
- pip3 install 包名 例如:pip3 install Pandas
- pip3 uninstall 包名 例如: pip3 uninstall Pandas
二、mybatis plus 樂觀鎖配置
import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;
/**
* mybatis plus 樂觀鎖配置
* @author nick
*/
@EnableTransactionManagement
@Configuration
public class MybatisPlusConfig {
/**
* 樂觀鎖
*/
@Bean
public OptimisticLockerInterceptor optimisticLockerInterceptor() {
return new OptimisticLockerInterceptor();
}
}
三、@Scheduled定時(shí)任務(wù)升級(jí)分布式定時(shí)任務(wù)
/**
* DisSchedule切面
*/
@Order(100)
@Aspect
@Slf4j
public class DisScheduleAspect {
public static final String SERVER_NAME = "serverName";
private final IDisScheduleService disScheduleService;
private final String serverName;
public DisScheduleAspect(
IDisScheduleService disScheduleService,
Environment environment) {
Preconditions.checkNotNull(disScheduleService);
this.disScheduleService = disScheduleService;
Preconditions.checkNotNull(environment);
String serverName = environment.getProperty(SERVER_NAME);
Preconditions.checkArgument(!Strings.isNullOrEmpty(serverName));
this.serverName = serverName;
}
/**
* 方法上有注解SaveLog
*/
@Pointcut(value = "@annotation(com.citydo.xclouddesk.interceptor.annotation.DisSchedule)")
public void disScheduleAnnotation() {
}
@Around(value = "disScheduleAnnotation() && @annotation(disSchedule)")
public Object disSchedule(ProceedingJoinPoint joinPoint, DisSchedule disSchedule) throws Throwable {
Preconditions.checkNotNull(disSchedule);
// 當(dāng)前時(shí)間
Date curDate = TimeUtil.getCurDate();
// 獲取name
String name = disSchedule.name();
if (Strings.isNullOrEmpty(name)) {
// 方法名
Signature signature = joinPoint.getSignature();
name = signature.getName();
}
// 時(shí)間間隔
int duration = disSchedule.duration();
if (duration <= 0) {
log.error(
"disSchedule fail, duration {} is less or equal 0, name : {}",
duration,
name
);
return null;
}
// 時(shí)間間隔的單位
TimeUnit unit = disSchedule.unit().getUnit();
// 轉(zhuǎn)化為毫秒
long millis = unit.toMillis(duration);
// 獲取當(dāng)前任務(wù)所屬的開始時(shí)間
Date taskDate = TimeUtil.getMillisDate(curDate, (int) millis);
// 當(dāng)前服務(wù)是否屬于線上服務(wù)
if (!disScheduleService.serverNameIsValid(serverName)) {
log.info(
"disSchedule fail, serverName is invalid, serverName : {} , name : {} , taskDate : {}",
serverName,
name,
TimeUtil.specialFormatToDateStr(taskDate)
);
return null;
}
if (!disScheduleService.tryGetLock(name, taskDate, serverName)) {
log.info(
"Distributed lock not acquired, name : {} , taskDate : {}",
name,
TimeUtil.specialFormatToDateStr(taskDate)
);
return null;
}
// 執(zhí)行正常的方法邏輯
return joinPoint.proceed();
}
}
/**
* 在方法執(zhí)行之前,決定當(dāng)前是否需要執(zhí)行定時(shí)調(diào)度任務(wù)
* @author nick
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface DisSchedule {
/**
* 定時(shí)調(diào)度任務(wù)的名稱(默認(rèn)是方法名)
*/
String name() default "";
/**
* 任務(wù)的間隔時(shí)間
*/
int duration();
/**
* duration的時(shí)間單位(默認(rèn):分鐘)
*/
DisScheduleUnit unit() default DisScheduleUnit.MINUTES;
}
/**
* 分布式定時(shí)調(diào)度服務(wù)
* @author nick
*/
public interface IDisScheduleService {
/**
* 重新加載
*/
void reload();
/**
* serverName是否有效
*/
boolean serverNameIsValid(String serverName);
/**
* 嘗試獲取鎖
*/
boolean tryGetLock(String taskName, Date taskDate, String serverName);
/**
* 添加當(dāng)前的serverName
*/
void addServerName(String serverName);
/**
* 移除當(dāng)前的serverName
*/
void removeServerName(String serverName);
}
/**
* redis實(shí)現(xiàn)
*/
@Slf4j
@Service
public class DisScheduleRedisServiceImpl implements IDisScheduleService {
public static final String DIS_SCHEDULE_SERVER_NAME = "disScheduleServerName";
private final IRedisManager redisManager;
public DisScheduleRedisServiceImpl(IRedisManager redisManager) {
Preconditions.checkNotNull(redisManager);
this.redisManager = redisManager;
}
@Override
public void reload() {
// do nothing
}
@Override
public boolean serverNameIsValid(String serverName) {
try {
return redisManager.isMember(DIS_SCHEDULE_SERVER_NAME, serverName);
} catch (Exception e) {
log.error(
"DisScheduleRedisServiceImpl-serverNameIsValid fail, serverName : {} , exception : {}",
serverName,
e
);
}
return false;
}
@Override
public boolean tryGetLock(String taskName, Date taskDate, String serverName) {
try {
return redisManager.setNx(
taskName + "_" + TimeUtil.specialFormatToDateStr(taskDate),
serverName
);
} catch (Exception e) {
log.error(
"DisScheduleRedisServiceImpl-tryGetLock fail, taskName : {} , taskDate : {} , serverName : {} , exception : {}",
taskName,
TimeUtil.specialFormatToDateStr(taskDate),
serverName,
e
);
}
return false;
}
@Override
public void addServerName(String serverName) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(serverName));
redisManager.sAdd(DIS_SCHEDULE_SERVER_NAME, serverName);
}
@Override
public void removeServerName(String serverName) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(serverName));
redisManager.sRem(DIS_SCHEDULE_SERVER_NAME, serverName);
}
// @DisSchedule(name = "testSchedule", duration = 1, unit = DisScheduleUnit.MINUTES)
// @Scheduled(cron = "0 0/1 * * * ?")
// public void testSchedule() {
// logger.info("輸出");
// }
}
public interface IRedisManager {
/**
* 向set中添加元素
*/
boolean sAdd(String key, String value);
/**
* set中是否存在value
*/
boolean isMember(String key, String value);
/**
* 移除set中的元素
*/
void sRem(String key, String value);
/**
* 設(shè)置字符串的值(如果不存在的話)
*/
boolean setNx(String key, String value);
}
/**
* 基于jedis實(shí)現(xiàn)的redisManager
*/
@Service
public class JedisManagerImpl implements IRedisManager {
@Autowired
private JedisPoolClient jedisPoolClient;
/**
* 返回1說明添加成功,返回0說明已經(jīng)存在
* @param key
* @param value
* @return
*/
@Override
public boolean sAdd(String key, String value) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(key));
Preconditions.checkArgument(!Strings.isNullOrEmpty(value));
return jedisPoolClient.sAdd(key, value) == 1L;
}
@Override
public boolean isMember(String key, String value) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(key));
Preconditions.checkArgument(!Strings.isNullOrEmpty(value));
return jedisPoolClient.isMember(key, value);
}
@Override
public void sRem(String key, String value) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(key));
Preconditions.checkArgument(!Strings.isNullOrEmpty(value));
jedisPoolClient.sRem(key, value);
}
@Override
public boolean setNx(String key, String value) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(key));
Preconditions.checkArgument(!Strings.isNullOrEmpty(value));
return jedisPoolClient.setNX(key, value);
}
}
參考:https://github.com/death00/dis-schedule
四、Multiset與HashMap、Multimap關(guān)系

總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- python深度學(xué)習(xí)tensorflow實(shí)例數(shù)據(jù)下載與讀取
- 使用Python、TensorFlow和Keras來進(jìn)行垃圾分類的操作方法
- Python基于TensorFlow接口實(shí)現(xiàn)深度學(xué)習(xí)神經(jīng)網(wǎng)絡(luò)回歸
- Python基于Tensorflow2.X實(shí)現(xiàn)汽車油耗預(yù)測(cè)
- Python tensorflow與pytorch的浮點(diǎn)運(yùn)算數(shù)如何計(jì)算
- python深度學(xué)習(xí)tensorflow訓(xùn)練好的模型進(jìn)行圖像分類
- python深度學(xué)習(xí)tensorflow1.0參數(shù)和特征提取
相關(guān)文章
pandas獲取某列最大值的所有數(shù)據(jù)的兩種方法
本文主要介紹了pandas獲取某列最大值的所有數(shù)據(jù)實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2024-07-07
pytorch環(huán)境配置及安裝圖文詳解(包括anaconda的安裝)
這篇文章主要介紹了pytorch環(huán)境配置及安裝圖文詳解(包括anaconda的安裝),本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2023-04-04
使用python-cv2實(shí)現(xiàn)Harr+Adaboost人臉識(shí)別的示例
這篇文章主要介紹了使用python-cv2實(shí)現(xiàn)Harr+Adaboost人臉識(shí)別的示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-10-10
用Python編寫一個(gè)簡(jiǎn)單的俄羅斯方塊游戲的教程
這篇文章主要介紹了用Python編寫一個(gè)簡(jiǎn)單的俄羅斯方塊游戲的教程,編寫俄羅斯方塊幾乎是每門編程語言基礎(chǔ)學(xué)習(xí)后的必備實(shí)踐,需要的朋友可以參考下2015-04-04
python 將有序數(shù)組轉(zhuǎn)換為二叉樹的方法
這篇文章主要介紹了python 將有序數(shù)組轉(zhuǎn)換為二叉樹的方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03
Python?Pandas數(shù)據(jù)分析的使用完整教學(xué)
本文介紹了高效數(shù)據(jù)處理的全流程技術(shù)方案,涵蓋數(shù)據(jù)接入、診斷、清洗、轉(zhuǎn)換及時(shí)序分析五大環(huán)節(jié),文中的示例代碼講解詳細(xì),有需要的小伙伴可以了解下2026-06-06

