0

I am trying to import some packages into Pycharm, Pandas and another package (pyTQA) into my python code. I have a virtual environment set up with these packages inside of there. This is my code now:

from pyTQA import tqa
import sys
import pandas as pd

Neither pyTQA nor pandas will import. Maybe it's something with my main.py file? (where my code is). Is that supposed to be in the virtual env folder? I am new to python and appreciate the help.

I get the error 'ModuleNotFoundError'

This is a picture of the folders in PyCharm. The code is in main.py

Mattias Weiland
  • 61
  • 1
  • 2
  • 6
  • No, that is a different error. Mine will not import on any IDE. The error is just 'ModuleNotFoundError' – Mattias Weiland Jul 09 '21 at 20:54
  • You haven't explained if you set the Python interpreter in the IDE, so that is most likely the problem that leads to `ModuleNotFoundError` you haven't said anything in the question that would indicate you configured the interpreter correctly. – bad_coder Jul 09 '21 at 20:56

1 Answers1

0

I think you may get a better answer by providing a bit more context.

  1. Virtual environment and packages - You mention you have a virtual environment set up with these packages inside of there.Can you confirm that the packages have been installed in the virtual environment? I'm more experienced with Anaconda Navigator, but for any new virtual environment the packages must be installed specifically in that virtual environment. Is it possible you have them installed elsewhere? Without seeing more, I'm leaning towards this being the issue. Make sure to check out PyCharm documentation on managing requirements, if you haven't yet!

  2. Sharing Errors - You mentioned that neither package will import. Does it throw some error code? Can you share this in your post?

  3. Share code - You ask towards the end if it might be something in your main.py file. Is there something in particular you're concerned about? If so, please share this in your post.

Ben Witte
  • 61
  • 1
  • 3
  • What do you mean installed in the virtual environment? I use Anaconda as well, and I did 'pip install xxx' and 'conda install xxx' for both. But tqa is just a .py file in the folder pyTQA with some functions, I thought I can just access the functions this way. – Mattias Weiland Jul 09 '21 at 20:50
  • So this is a pretty complicated concept, and depending on your experience with other programming languages, you may actually know more than me - sorry if I say things you already know. If you're working in a virtual environment, it's pretty much like a blank slate - like a partitioned part of a drive, it has more or less nothing on it. You may have installed those packages on your computer, but if you didn't install them in the VE, then the script that is running in the VE doesn't actually have access to them. 1/2 – Ben Witte Jul 09 '21 at 20:58
  • For info on working in a virtual environment in PyCharm, check out the documentation: https://www.jetbrains.com/help/pycharm/creating-virtual-environment.html#existing-environment. For information on working in VE's for Python more generally, i recommend this: https://towardsdatascience.com/environments-conda-pip-aaaaah-d2503877884c – Ben Witte Jul 09 '21 at 21:00