Search code examples
pythonpython-3.8concurrent.futures

Code is running in VS Code but not in Terminal


My python script is perfectly running in vs code, but when I run it via terminal I get the error message "ImportError: No module named concurrent.futures"

I use a venv and a pip list shows:

   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  

The import in my code looks like this:

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

I also tried:

  • from futures import ThreadPoolExecutor
  • import concurrent.futures
  • installing futures not in a venv
  • updating futures
  • uninstalling futures

EDIT: my goal is to run the script daily so I followed this tutorial Link and I'm stuck at the point were I create a Unix executable file. When I run this file the terminal shows the error.


Solution

  • I figured it out my self and it was quite simple...

    In the tutorial they create this file with

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

    The solution was to activate the venv before running the .py file.

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

    Thanks to Niklas Mertsch, your question brought me there.