python-dotenv的使用

python-dotenv的使用

  项目地址:https://github.com/theskumar/python-dotenv

  首先看一下github上项目的介绍:

  Reads the key,value pair from .env and adds them to environment variable. 

  大概意思就是在我们做项目时,我们可以把所有用到的环境变量写到.env文件里,然后以k,v的方式读取作为环境变量。

 

举个例子Python连接postgresql数据库:

python代码:

#coding:utf-8
import psycopg2 
from dotenv import find_dotenv,load_dotenv
import os
load_dotenv(find_dotenv())
conn=False
conn = psycopg2.connect(os.environ.get('URL'))
if conn:
        print '连接成功!'

 

.env内容:

URL=postgresql://postgres:123456@127.0.0.1/postgres
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
ERROR: Could not find a version that satisfies the requirement python-dotenv (from versions: none) 是一个错误提示,意味着无法找到适合的python-dotenv版本。这可能是由于以下原因之一导致的: - 您的python-dotenv版本太旧,不与您当前使用的Python版本兼容。 - 在您使用的Python环境中没有安装python-dotenv。 为了解决这个问题,您可以尝试以下几种方法: 1. 确保您的Python环境已经安装了python-dotenv。可以使用以下命令来安装最新版本的python-dotenv: ``` pip install python-dotenv ``` 2. 如果您已经安装了python-dotenv,但仍然遇到问题,请确保您的python-dotenv版本与您当前使用的Python版本兼容。您可以通过在命令行中输入以下命令来检查python-dotenv版本: ``` pip show python-dotenv ``` 确保版本号与您当前使用的Python版本兼容。 3. 如果上述方法仍然无法解决问题,您可以尝试升级您的Python版本。使用较新的Python版本可能会提供对最新软件包的支持。 通过执行上述步骤,您应该能够解决ERROR: Could not find a version that satisfies the requirement python-dotenv (from versions: none)的问题。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [bitvarybot:Upbit波动性突破](https://download.csdn.net/download/weixin_42100971/15559891)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [ERROR: Could not find a version that satisfies the requirement PIL (from versions: none)解决方案](https://blog.csdn.net/weixin_43178406/article/details/130536747)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值