我正在尝试使用 pipreqs 包生成一个 requirements.txt 文件。按照文档的示例,我一直无法使其工作。
看起来很简单,文档告诉我在终端中使用这个命令:
$ pipreqs /home/project/location
Run Code Online (Sandbox Code Playgroud)
就我而言,这是我项目的位置:
$ pipreqs /Users/ep9k/Desktop/UVA\ Big\Deal
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/ep9k/Desktop/UVA BigDeal/requirements.txt'
Run Code Online (Sandbox Code Playgroud)
错误信息是正确的,那个目录下没有requirements.txt文件。我正在尝试使用 pipreqs 创建 requirements.txt 文件。
阅读文档后,pipreqs 应该扫描 python 文件中的导入语句,并基于此构建 requirements.txt 文档。所以我也尝试了这个,使用我想要 pipreqs 扫描的文件:
$ pipreqs /Users/ep9k/Desktop/UVA\ Big\Deal/1FigrFunctions.py
Run Code Online (Sandbox Code Playgroud)
我收到了这个错误,这与上面的几乎相同:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/ep9k/Desktop/UVA BigDeal/1FigrFunctions.py/requirements.txt'
Run Code Online (Sandbox Code Playgroud)
我相信解决方案是显而易见的。我究竟做错了什么?
我试图找出为什么我无法使用 psycopg2 访问 PostgreSQL 数据库中的特定表。我正在运行 PostgreSQL 11.5
如果这样做,我可以连接到相关数据库并读取其中的所有表:
import psycopg2
try:
connection = psycopg2.connect(user = "postgres", #psycopg2.connect() creates connection to PostgreSQL database instance
password = "battlebot",
host = "127.0.0.1",
port = "5432",
database = "BRE_2019")
cursor = connection.cursor() #creates a cursor object which allows us to execute PostgreSQL commands through python source
#Print PostgreSQL version
cursor.execute("""SELECT table_name FROM information_schema.tables
WHERE table_schema = 'public'""")
for table in cursor.fetchall():
print(table)
Run Code Online (Sandbox Code Playgroud)
结果如下:
('geography_columns',)
('geometry_columns',)
('spatial_ref_sys',)
('raster_columns',)
('raster_overviews',)
('nc_avery_parcels_poly',)
('Zone5e',)
('AllResidential2019',)
#....etc....
Run Code Online (Sandbox Code Playgroud)
我感兴趣的表是最后一个表“AllResidential2019”
因此,我尝试连接到它并通过执行以下操作来打印内容: …
我一直在学习和试验装饰器。我理解它们的作用:它们允许您通过向现有函数添加功能而不更改它们来编写模块化代码。
我找到了一个很好的线程,它通过解释这里的所有来龙去脉,真正帮助我学习了如何做到这一点:如何制作函数装饰器链?
但是这个线程(以及我看过的其他资源)缺少的是为什么我们需要装饰器语法?为什么我需要嵌套函数来创建装饰器?为什么我不能只使用一个现有的函数,编写另一个具有一些额外功能的函数,然后将第一个函数输入到第二个函数中以使其执行其他操作?
仅仅是因为这是约定吗?我错过了什么?我认为我的经验不足在这里表现出来。
我有一些使用 itertools.zip_longest 压缩在一起的数据
import itertools
names = 'Tim Bob Julian Carmen Sofia Mike Kim Andre'.split()
locations = 'DE ES AUS NL BR US'.split()
confirmed = [False, True, True, False, True]
zipped_up = list(itertools.zip_longest(names, locations, confirmed))
Run Code Online (Sandbox Code Playgroud)
如果我按照现在的方式打印 zipped_up,我会得到以下信息:
[('Tim', 'DE', False), ('Bob', 'ES', True),
('Julian','AUS', True), ('Carmen', 'NL', False),
('Sofia', 'BR',True), ('Mike', 'US', None),
('Kim',None, None),('Andre', None, None)]
Run Code Online (Sandbox Code Playgroud)
这很好,缺失值默认为“无”。 现在我想将“无”值更改为 '-'。
似乎我应该能够在以下嵌套循环中这样做。如果我在下面的代码中包含一个打印语句,看起来一切都按我想要的方式工作:
for items in zipped_up:
for thing in items:
if thing == None:
thing = '-'
print(thing)
Run Code Online (Sandbox Code Playgroud)
但是如果我再次打印 zipped_up …
我正在尝试部署一个简单的 python Flask 应用程序。我过去部署过一个非常类似的应用程序,在 requests.txt 文件夹中具有所有相同的要求。
在尝试使用“git push heroku master”将我的存储库推送到heroku时,heroku执行了它的操作并最终给出了以下错误:
remote: ERROR: Failed building wheel for pandas
remote: Successfully built numpy
remote: Failed to build pandas
remote: ERROR: Could not build wheels for pandas which use PEP 517 and cannot be installed directly
remote: ! Push rejected, failed to compile Python app.
remote:
remote: ! Push failed
remote: Verifying deploy...
remote:
remote: ! Push rejected to isitdry.
remote:
To https://git.heroku.com/isitdry.git
Run Code Online (Sandbox Code Playgroud)
所以熊猫有一些它不喜欢的地方。
这是我的requirements.txt 的样子:
certifi==2020.6.20
chardet==3.0.4
click==7.1.2
Flask==1.1.2
gunicorn==20.0.4
idna==2.10
itsdangerous==1.1.0 …Run Code Online (Sandbox Code Playgroud) python ×5
python-3.x ×4
dependencies ×1
flask ×1
heroku ×1
pandas ×1
postgresql ×1
psycopg2 ×1