Entering edit mode
9.1 years ago
niharraul
•
0
Hello,
Trying to access a VCF file (PyVCF 0.6.7) using the python script and the library, both provided on the following website:
https://pypi.python.org/pypi/PyVCF
import vcf
vcf_reader = vcf.Reader(open('example_GRCh37.vcf', 'r'))
for x in vcf_reader:
print (x)
The error is as follows:
Traceback (most recent call last):
File "/Volumes/Documents HD/Python_test/Convert_TO_VCF_USING_LIBRARAY.py", line 3, in <module>
vcf_r = vcf.Reader(open('example_GRCh37.vcf'))
AttributeError: 'module' object has no attribute 'Reader'
It would be great if you could suggest something to fix this error
Hi,
Thanks for the reply. I am still getting the same error. Is it possible that I am running the code on the default python 2.7 version on mac and I should be upgrading it to higher that 3.4 or something.
Regards
Do you have a file in the same directory called "vcf.py"? I think python may be trying to call vcf.py instead of PyVCF.
It should be fine on 2.7. I'm using 2.7 on OS X, and it works fine. What does "import vcf" return?
(1) Since Mac OSX has default installation of python 2.7. But as per the suggestions when I tried to install the library using the command
easy_install pyvcf
it throws the following error:(2) So I manually (not through command line) downloaded it visiting the website and that is clicking on the green button and then unzipping the folder in the appropriate directory. It was throwing error in the code so I copy pasted the "vcf" folder from the downloaded, unzipped PyVCF-0.6.7 folder.Since I import the vcf library in the code.Now for the same code ,I am getting the following error:
(3)No, I am not having any "vcf.py" in the directory.
(4) I am using PyCharm IDE
You have to be root to use easy_install. Try "sudo easy_install pyvcf". You will be prompted for your password.
Thanks for the reply.
I could install the pyvcf as suggested with a password and with the sudo command and then restarted everything but getting the same error
Thanks again, really appreciate for your help.
Regards
It's actually a different error specific to Python 3. You're using Python 3, and you should be using Python 2.7.
But the default installation is for python 2.7 since I am using mac.
In your error message, it says
The error message:
is specific to Python 3, where the "dict.iteritems" was changed to "dict.items". Python 2.7 should not throw this error.
How are you running this script? Are you using the terminal? I.e. Typing:
No , I am using Pycharm IDE ... I guess Pycharm might be using Python 3