代码在VS Code中运行,但不在终端中运行。

问题描述 投票:0回答:1

我的 python 脚本在 vs 代码中运行得很完美,但当我通过终端运行时,我得到错误信息 "ImportError: No module named concurrent.futures"

我使用一个venv和一个pip列表显示。

   Package        Version   
-------------- ----------
appdirs        1.4.4     
attrs          19.3.0    
beautifulsoup4 4.9.1     
black          19.10b0   
certifi        2020.4.5.2
chardet        3.0.4     
click          7.1.2     
futures        3.1.1     
idna           2.9       
pathspec       0.8.0     
pip            19.2.3    
regex          2020.6.8  
requests       2.23.0    
setuptools     41.2.0    
soupsieve      2.0.1     
toml           0.10.1    
typed-ast      1.4.1     
urllib3        1.25.9  

我的代码中的导入是这样的

import concurrent.futures
import csv
import os
import re
import time
from datetime import date
import requests
from bs4 import BeautifulSoup

我也试了一下

  • from futures import ThreadPoolExecutor
  • import concurrent.futures
  • 安装期货,而不是在venv里
  • 更新期货
  • 卸载期货

EDIT:我的目标是每天运行脚本,所以我按照这个教程来做 链接我卡在了创建一个Unix可执行文件的地方。当我运行这个文件时,终端显示错误。

python python-3.8 concurrent.futures
1个回答
0
投票

我自己想出来的,很简单......

在教程中,他们创建这个文件的目的是

#!/bin/sh
Python /Users/yanissilloul/Documents/instabot-master/examples/like_hashtags_copy.py neonphotography

解决方法是在运行.py文件之前激活venv。

#!/bin/sh
source .venv/bin/activate
Python /Users/yanissilloul/Documents/instabot-master/examples/like_hashtags_copy.py neonphotography

感谢Niklas Mertsch,你的问题让我找到了答案。

© www.soinside.com 2019 - 2024. All rights reserved.