Entering edit mode
16 months ago
anasjamshed ▴ 120
I am trying this code:
import vcf vcf_reader = vcf.Reader(open('C:/Users/USER/Desktop/isiah/VCFs_1/test_1.vcf', 'r')) for record in vcf_reader: print (record)
But its giving me import error although i already installed PyVCF package:
Kindly help me to fix it?
I suspect you installed pyVCF package via pip although you don't provide that information. It's always good to provide such details. Just now I tried myself and although I found pip says it is successful after many failed attempt with various versions, I saw the same thing as you are seeing at present when I try to import. Specifically import fails. Which generally means something about the installation was not correct, despite what pip reported.
I looked around and found this post which is a little more recent than the software itself. According to the date in the upper right corner here, pyVCF hasn't been updated in a long time. Abandoned / not actively-maintained software is usually a sign that you are more likely to encounter issues.
I was successful at both installation and subsequent import by following the recommendation in this comment here dated two years ago by steve:
It looks like you are using this in Jupyter based on this image here? (You don't provide this information in either post. The more information you provide, the better your answers will be.) Assuming you do have recent Jupyter notebook or JupyterLab, try running this in a cell in your notebook to follow that advice:
That uses a magic command that has recently been added to IPython kernel that is commonly used in modern Jupyter to run Python. The magic
%conda installand related
%pip installcommands insure that they install the software to the environment that the current notebook is using, see more about them here. Restart the kernel, and then in another cell try
import vcf. If that import attempt works without error, you can use the rest of the code you posted.
The post at Biostars I pointed to also suggests some alternatives instead of this software that has not been developed in nearly six years.
So it simply means we should install older versions of any package by using conda instead of pypi
No, it doesn't 100% mean if it is old than try conda in all cases. However, it can be helpful when you run into a problem to try another route. And conda is a great route. And in this case others had suggested it is more reliable for this software. Ideally, it is best to avoid software that isn't being actively developed/maintained because you are going to be having a more difficult go of it. And your experience usually gets tougher with more time since it was last updated. I will say if you are working in a notebook and want things to work, pretty much 100% of the time try the magics route with
%conda installto see if you can bypass issues you may encounter with your environment. Don't use
!anymore in the notebook with
conda. (There's a lot of outdated information out there suggesting that.) I think by default if you leave off the
conda installuse the magics route by default. Meaning the
%gets added by automagics.
cross posted: https://stackoverflow.com/questions/70838449