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.
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.
Related
I'm using the Google Calendar API to fetch some events and I'm using a venv to house all the packages required, and I've run into a simple problem: google.auth.transport.requests can't function correctly, citing the requests package is not installed.
Code and error:
The problem can be observed using a single line of code:
from google.auth.transport.requests import Request
The following error is dumped to the console from google.auth.transport.requests (at the bottom of two tracebacks):
File "<string>", line 3, in raise_from
ImportError: The requests library is not installed, please install the requests package to use the requests transport.
Failed attempts
Deleting and remaking the venv.
Install modules with --no-cache-dir and --ignore-installed.
Information
Executing import requests or from google.auth.transport.requests import Request from the console from env\Scripts\python works without problem.
The same lines when put in a file temp.py when placed inside the following directories execute in the following manner:
AutoMate\: Safe
AutoMate\src\: Safe
AutoMate\src\sources\: Error
AutoMate\src\sources\temp\: Safe (sources\temp only made for debugging)
AutoMate\src\sources\util\: Safe.
Note: All tests here and below have been ran from AutoMate\ using env\Scripts\python and env\Scripts\pip.
None of the google auth modules have been installed in the pip outside of the venv.
The project structure is as follows:
AutoMate
| temp.py
├───env
│ ├───Include
│ ├───Lib
│ └───Scripts
└───src
│ AutoMate.pyw
│
└───sources
│ calendar.py --> Problematic file
│ whatsapp.py
│ __init__.py
│
└───util
Output of env\Scripts\pip list:
Package Version
------------------------ ---------
cachetools 4.2.1
certifi 2020.12.5
chardet 4.0.0
google-api-core 1.26.1
google-api-python-client 2.0.2
google-auth 1.27.1
google-auth-httplib2 0.1.0
google-auth-oauthlib 0.4.3
googleapis-common-protos 1.53.0
httplib2 0.19.0
idna 2.10
oauthlib 3.1.0
packaging 20.9
pip 21.0.1
protobuf 3.15.5
pyasn1 0.4.8
pyasn1-modules 0.2.8
pyparsing 2.4.7
pytz 2021.1
requests 2.25.1
requests-oauthlib 1.3.0
rsa 4.7.2
selenium 3.141.0
setuptools 49.2.1
six 1.15.0
uritemplate 3.0.1
urllib3 1.26.3
Solution
Any file that uses google.auth.transport.requests must not have any file named exactly calendar.py** in the same directory as itself.
Any* other filename works, even calendar.python and Calendar.py.
** On testing it seems like requests.py and datetime.py are also some invalid names, while math.py and time.py seem to work fine, maybe the invalid names are used internally? Need further knowledge.
Reason
It looks like some there's some internal interference to me, I'm hoping someone will respond with the reason to this problem as well.
There is a try-except block within google.auth.transport.requests while importing requests package, which defaults to that error message even if the package was already installed. Code
Trying to import requests directly in REPL revealed that there was in issue with from collections import Mapping (I was using Python v3.10 at the time). As suggested here, downgrading my Python version and creating a new venv helped me with this problem.
I've spent half a day trying to figure it out on my own but now I've run out of ideas and googling requests.
So basically what I want is to connect to our Snowflake database using snowflake-connector-python package. I was able to install the package just fine (together with all the related packages that were installed automatically) and my current pip3 list results in this:
Package Version
-------------------------- ---------
asn1crypto 1.3.0
azure-common 1.1.25
azure-core 1.6.0
azure-storage-blob 12.3.2
boto3 1.13.26
botocore 1.16.26
certifi 2020.6.20
cffi 1.14.0
chardet 3.0.4
cryptography 2.9.2
docutils 0.15.2
gitdb 4.0.5
GitPython 3.1.3
idna 2.9
isodate 0.6.0
jmespath 0.10.0
msrest 0.6.17
oauthlib 3.1.0
oscrypto 1.2.0
pip 20.1.1
pyasn1 0.2.3
pyasn1-modules 0.0.9
pycparser 2.20
pycryptodomex 3.9.8
PyJWT 1.7.1
pyOpenSSL 19.1.0
python-dateutil 2.8.1
pytz 2020.1
requests 2.23.0
requests-oauthlib 1.3.0
s3transfer 0.3.3
setuptools 47.3.1
six 1.15.0
smmap 3.0.4
snowflake-connector-python 2.2.8
urllib3 1.25.9
wheel 0.34.2
Just to be clear, it's a clean python-venv although I've tried it on the main one, too.
When running the following code in VScode:
#!/usr/bin/env python
import snowflake.connector
# Gets the version
ctx = snowflake.connector.connect(
user='user',
password='pass',
account='acc')
I'm getting this error:
AttributeError: module 'snowflake' has no attribute 'connector'
Does anyone have any idea what could be the issue here?
AttributeError: module 'snowflake' has no attribute 'connector'
Your test code is likely in a file named snowflake.py which is causing a conflict in the import (it is ending up importing itself). Rename the file to some other name and it should allow you to import the right module and run the connector functions.
Try importing 'connector' explicitly. I had the same error.
import pandas as pd
import snowflake as sf
from snowflake import connector
When I had this issue I had both the snowflake and snowflake-connector-python module installed in my environment, so it was confused on which one to use. If you're trying to use connector, just pip uninstall snowflake
If you have installed both snowflake and snowflake-connector-python, just uninstalling snowflake package will resolve the issue.
_
To list installed python packages, use command
pip list
I installed python 3.6 again.
I removed this line from code
#!/usr/bin/env python
It worked.
pip install snowflake-connector-python
Have you tried using this package instead in the jupyter notebook?
If anyone comes across this same issue and doesn't get reprieve from the above fixes, my install had a snowflake.py file saved to the site-packages folder.
This caused the 'import snowflake.connector' statement to attempt to import from the snowflake.py file instead of the snowflake folder, and of course couldn't find the connector module since the .py file isn't a package. Renaming or moving that file solved my problem.
I had a sub-folder named snowflake, but depending on how I run the script it either could or could not import the snowflake.connector.
I've tried import weka package in Pycharm. But it got an error.
This is for Python 3.7.4 on windows 10. And I've installed java bridge and Weka successfully.
Package Version
------------------- -------
arff 0.9
javabridge 1.0.18
numpy 1.17.3
pandas 0.25.2
pip 19.3.1
python-dateutil 2.8.0
python-weka-wrapper 0.3.15
pytz 2019.3
setuptools 40.8.0
six 1.12.0
weka 1.0.6
and I type:
import weka.core
and get the error:
File "C:/Users/dell/PycharmProjects/lab2/Source.py", line 2, in <module>
import weka.core
ModuleNotFoundError: No module named 'weka.core'
So how to fix it? Thank you
weka.core is not a Python module, as the error states.
What are you trying to achieve with this import?
If you are trying to import the jvm module (eg for starting/stopping the JVM), then do something like import weka.core.jvm as jvm.
I have installed docopt by typing pip3 install docopt and now it is well installed: You can see it on the list
umr5558-c02gl0y6drjm:Concatenate etudiant$ pip3 list
Package Version
--------------- -------
biopython 1.71
buildozer 0.34
cycler 0.10.0
docopt 0.6.2
kiwisolver 1.0.1
matplotlib 2.2.2
nose 1.3.7
numpy 1.14.2
pexpect 4.5.0
pip 10.0.0
ptyprocess 0.5.2
pyparsing 2.2.0
python-dateutil 2.7.2
pytz 2018.4
scipy 1.0.1
setuptools 39.0.1
sh 1.12.14
six 1.11.0
virtualenv 15.2.0
wheel 0.30.0
But when I try to import docoport from docopt on python3 it raises:
ModuleNotFoundError: No module named 'docopt'
Does someone have an idea?
Here is the path:
umr5558-c02gl0y6drjm:Concatenate etudiant$ pip3.6 install docopt
Requirement already satisfied: docopt in /usr/local/lib/python3.6/site-packages (0.6.2)
Here is the import section:
from Bio import codonalign
from Bio.Align import MultipleSeqAlignment
from Bio.SeqRecord import SeqRecord
from Bio.Alphabet import IUPAC
from Bio.Seq import Seq from Bio import AlignIO
from Bio import pairwise2
from Bio.codonalign.codonseq import _get_codon_list, CodonSeq, cal_dn_ds
import scipy
from Bio.Align.Applications import MuscleCommandline
from Bio.Align import MultipleSeqAlignment
from scipy.linalg import expm
from Bio import SeqIO
import sys
import numpy as np
from docopt import docopt
Thanks
Hello
Try it
sudo apt install python3-docopt
I had a similar problem and this is how I solved it:I also had installed docopt via pip install docopt, and I have both python 2 and 3 in my mac. The problem is that docopt is installed for python 3, but when running the .py file in terminal, it ran in python 2 by default. Just add #!/usr/bin/env python3 to the very beginning of your .py file, and it should fix your issue.
I have the following problem.
I have tried to install the pydicom package in python 2.7 using the following command (windows, anaconda setup):
conda install -c conda-forge pydicom
everything seems to work fine, the package seems to be installed.
I type
conda list
and in the list I see
pydicom 0.9.8 <pip>
I open spyder, or pycharm, type
import pydicom
and I get
ImportError: No module named pydicom
I have no idea what am I doing wrong. I went through http://conda.pydata.org/docs/using/pkgs.html and everything seems to be fine.
Please assist.
Since you are using 0.9.8, you actually need import dicom rather than import pydicom.
Due to this confusion, it will be import pydicom in version 1.0.0 and later.
I suggest you either update Python Version > 3.0, so that the output for conda list shows something like this:
(pip install pydicom)
pydicom 1.0.2 <pip>
python 3.6.4 h6538335_1
Now import using:
import pydicom #Preferable
==========================================================
Or install dicom instead of pydicom using:
(pip install pydicom-0.9.8)
pydicom 0.9.8 <pip>
python 2.7.0 h6538335_1
And then, import using:
import dicom
However, I strongly suggest that you install pydicom instead of dicom, since it is the upgraded version.