Python Module Not Importing in pycharm [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 26 days ago.
Improve this question
I am using Windows.
I just installed PyCharm and Conda. I also installed some modules via the command prompt.
I am attempting to import the 'requests' module.
This is what the Python Console says when I type in 'import requests':
ModuleNotFoundError: No module named 'requests'
Why is PyCharm not locating this 'requests' module? How do I get the module into the correct location to be imported?

Since you specifically stated: "Python Console says when I type in 'import requests'" it makes me feel like it's not an IDE/PyCharm issue, rather just an install/env issue. The Python environment does not have the requests module installed. It needs to be installed before you can import it.
More info on requests from on PyPi
Installing it is different depending on your environment and project structure.
For example, a basic install would be: pip install requests or python -m pip install requests
Or, depending on your configuration, perhaps pip3 install requests or pip install --user requests or poetry add requests etc etc all depending on your project environment.
Overall, as a side note, Python dependencies can be a nightmare if you are doing everything system-wide and working with different projects. It's highly suggested for each Python project to have its own virtual environment. An easy way to manage dependency versions and handle virtual environments is by using poetry which can manage these things in a config file + handle version locking. It'll solve these types of issues and ensure your project/dependencies can work properly on different systems.

Assuming you used pip to install the module, you can check if it is installed at all by typing "pip list" in the command prompt and then look for the module name and version.
If it does show up, go to PyCharm and go to:
File->Default Settings->Project Interpreter
If it doesn't show up there, click the +-button and then you should be able to add the packages you want.

Related

Module or Incorrect Python Version Problem?

I'm installing a bunch of python modules on my system that are specific to this code I am going to be working with. Specifically, I used pip install pyda to get the pyda module. To make sure I had gotten all the modules, I went through and ran some of the code snippets, and came across the following error:
ModuleNotFoundError: No module named 'pyda.utilities'
I tried using pip install pyda.utilities, but that honestly doesn't make sense, it should have just come with the pyda module. According to this website https://pypi.org/project/pyda/ it seems like it should come with the package. I tried determining if I just installed it in the wrong python version, but I'm having a difficult time forcing it to use the specific python version that I installed the module in (specifically, I tried to create an alias for /usr/bin/python3.7 or something like this as I have seen on other websites, but it just fusses at me that this is simply a directory, incredibly unhelpful because I can't find the corresponding executable, so I'm a bit confused here).
This is a very long question likely with a very simple answer, any thoughts or help on what the issue might be would be appreciated.
Edit: I have determined that it's a package problem, not a python problem. The command 'pip install pyda' is not actually installing everything, oddly enough, which is why it cannot find the pyda.utilities module. Unfortunately, I think this means I will have to install the package manually. I will keep this question posted because of the useful answer on virtual environments, so thanks everyone.
The answer is indeed straightforward. As #Chris indicated in the comments, start using virtual environments.
It's not as complicated as it sounds and there's plenty of tutorials on getting started with virtualenv for Python, like https://uoa-eresearch.github.io/eresearch-cookbook/recipe/2014/11/26/python-virtual-env/
The basic steps:
check you're using the version of Python you want in your virtual environment
if you don't, change directories to where it lives
ensure you have pip and it works
check if you have virtualenv and if you don't pip install virtualenv
create a virtual environment virtualenv /your/env/folder/here
activate the virtual environment with /your/env/folder/here/Scripts/activate
After that, just install the packages you need with pip and they will end up in your virtual environment, with no interference from other Python versions or packages.
Check your python version, if it does not work restart your computer and try run setup.py install on the python command line

Do executables like pip.exe require python to work?

I am relatively new to Python so please pardon my ignorance. I want to know answer to following questions
How does pip know the location to install packages that it installs? After a built of trial and error
I suspect that it maybe hardcoded at time of installation.
Are executables like pip.exe what they call frozen binaries? In essence, does it mean that pip.exe will run without python. Again after a bit of trial and error i suspect that it requires a python installation to execute.
P.S: I know about sys.prefix,sys.executable and sys.exec_prefix. If there is anything else on which the questions i asked on depends, pls link me to same.
PIP is a package manager for Python packages, or modules if you like.
pip when used with virtualenv will generally install packages in the path /lib//site-packages.
For example, I created a test virtualenv named test, and the django folder is in test/lib/python3.7/site-packages/django.
At the time of installation, you must have set up environment variables, and that is how pip recognizes directories.
pip.exe which is placed under path\Scripts needs a python installation and can't run without one. It is hardwired against a specific python interpreter, and can't install packages for another one. If you have 7 different python versions installed on your system, you will also have 7 different versions of pip.
Since it is bound so tightly, pip was at some point even included with the python standard library (see pep-0453 for details).
This also answers the other part of your question of how pip figures out the right location - there is only one location it can install to, the side-packages of the python interpreter it is bundled against.

Install (Or suggest to) missing imported Python modules on VS Code like PyCharm does

When we import a module that isn't currently installed on the Python used on the current environment, PyCharm suggest us to 'install missing module', if you click install, it'll install it automatically...
Is there any plugin for vscode that does that or something like that?
I want to import emoji for example, and like pycharm does, suggest me to install the missing module, so I won't have to do manually a pip install
Is there a plugin that does this for vscode?
Thank you
I think that your request is already ongoing on vscode-python extension:
https://github.com/microsoft/vscode-python/issues/8062
I suggest to follow this issue to see when it's ready for production.

ModuleNotFoundError: No module named 'win32crypt'

I'm trying to run a Python module for a school project and I am getting this error ModuleNotFoundError: No module named 'win32crypt' at line import win32crypt.
I've search the website for solution and encountered a post that states pywin32 is required. So I installed it with pip. I also tried installing pypiwin32. None of these installs worked. Now I've tried Dependency Walker to see if there are any dependencies missing and I see at least 100 DLLs that are. How can I fix the issue?
win32cryrpt is a part of the Windows Extensions for Python or pywin32. It is a wrapper around the Windows crypto API. It doesn't make sense to try and install it without pywin32 and if your install of that has failed then that is the problem you have to solve.
Please try pip install pypiwin32 again, being sure to execute it in the correct folder, which is the Scripts subfolder of the Python environment you want to install it in. You may have more than one Python installation without realizing it, and if you run pip from outside that folder, you may get a different instance of pip. The standard location for Python installations is C:\Program Files\Python3x. If the pip install doesn't complete as expected then edit your question to include the messages from the failed install. Did not work isn't enough to go on.

Import pip3 results in "ImportError: No module named 'pip3'

I am on Windows 7 with Python 3.5 installed on it.
Below is what happens:
import pip # works as expected
import pip3 # results in below error
ImportError: No module named 'pip3'
I have pip and pip3.exe both sitting in the same scripts folder.
I have scripts folder, site packages and python folder all added to my environment variable path (I have added it in user profile, as I do not have admin access to add to system variables)
Is there any solution which you all have tried and worked. I am new to python and any help is appreciated.
So, I learned that my problem with installing beautifulsoup was because of the firewall restriction in my organization, which I was relating to pip install.
I learned of the proxy settings and using that, got to install bs4 via the conda interpreter.
Thank you for all the answers, which made me think through on various aspects, which I would not have thought of without the probing questions brought up here.

Categories

Resources