python如何下載指定版本TensorFlow
更新時間:2024年03月28日 08:37:25 作者:灬點點
這篇文章主要介紹了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
驗證
pip3 list
pip3升級
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定時任務升級分布式定時任務
/**
* 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);
// 當前時間
Date curDate = TimeUtil.getCurDate();
// 獲取name
String name = disSchedule.name();
if (Strings.isNullOrEmpty(name)) {
// 方法名
Signature signature = joinPoint.getSignature();
name = signature.getName();
}
// 時間間隔
int duration = disSchedule.duration();
if (duration <= 0) {
log.error(
"disSchedule fail, duration {} is less or equal 0, name : {}",
duration,
name
);
return null;
}
// 時間間隔的單位
TimeUnit unit = disSchedule.unit().getUnit();
// 轉化為毫秒
long millis = unit.toMillis(duration);
// 獲取當前任務所屬的開始時間
Date taskDate = TimeUtil.getMillisDate(curDate, (int) millis);
// 當前服務是否屬于線上服務
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í)行之前,決定當前是否需要執(zhí)行定時調度任務
* @author nick
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface DisSchedule {
/**
* 定時調度任務的名稱(默認是方法名)
*/
String name() default "";
/**
* 任務的間隔時間
*/
int duration();
/**
* duration的時間單位(默認:分鐘)
*/
DisScheduleUnit unit() default DisScheduleUnit.MINUTES;
}
/**
* 分布式定時調度服務
* @author nick
*/
public interface IDisScheduleService {
/**
* 重新加載
*/
void reload();
/**
* serverName是否有效
*/
boolean serverNameIsValid(String serverName);
/**
* 嘗試獲取鎖
*/
boolean tryGetLock(String taskName, Date taskDate, String serverName);
/**
* 添加當前的serverName
*/
void addServerName(String serverName);
/**
* 移除當前的serverName
*/
void removeServerName(String serverName);
}
/**
* redis實現(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);
/**
* 設置字符串的值(如果不存在的話)
*/
boolean setNx(String key, String value);
}
/**
* 基于jedis實現(xiàn)的redisManager
*/
@Service
public class JedisManagerImpl implements IRedisManager {
@Autowired
private JedisPoolClient jedisPoolClient;
/**
* 返回1說明添加成功,返回0說明已經存在
* @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關系

總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關文章
我對PyTorch dataloader里的shuffle=True的理解
這篇文章主要介紹了我對PyTorch dataloader里的shuffle=True的理解,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-05-05
Python如何按單元格讀取復雜電子表格(Excel)的數(shù)據(jù)
這篇文章主要介紹了Python如何按單元格讀取復雜電子表格(Excel)的數(shù)據(jù)問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06

