As part of a web scraping class I've been instructed to download a few modules from the command terminal (requests, bs4, lxml). These have seemingly been successfully downloaded to my computer, yet my Jupyter Notebook AND PyCharm virtual environment cannot find them.
I am a beginner so I'm sure there are some big things I'm missing, any help would be appreciated.
How did you install Jupyter?
Wich package manager are you using? (eg. what did you type to install the packages?)
Wich modules can it find and which not?
Usually you want to make sure your modules are available in the environment you are using. ( Enviornments are like "versions" of python. You could run multiple versions like 3.7 and 3.9 on your Computer but also also different builds from one python version.)
Pycharm builds its own environment. Make sure you use the enivorment you installed your packages to in Pycharm. Pycharm allows you to modify and create new environments very easily
For PyCharm it might be useful to check out their help page.
I figure this could help: https://www.jetbrains.com/help/pycharm/configuring-python-interpreter.html#add_new_project_interpreter
The interpreter is basicly the a customized version of python. Pycharm keeps track of the modules you need for every project. So you want to create/select an interpreter which has the packages you have installed.
hope it helps
cheers
Related
This question already has answers here:
How to activate conda environment from powershell?
(8 answers)
Closed last year.
I'm trying to get on with Python coding rather than fiddling about with settings getting in the way of development. Alas, it is not meant to be.
1 - I've installed Python 3.9 in Windows 10 from the Windows Store (running python in a powershell and instructions therein).
2 - I'm using PyCharm IDE.
I am very familiar with JetBrains products and building php projects. The transition to Python is not as straightforward. When I setup a new project and want to run code I need to set my configuration for the virtual environment.
I range from not being able to run any code through to perfect success with a lack of being able to import libraries in between.
In my toolkit is:
a) Edit Configuation - selecting a python interpreter. This never seems to make any difference no matter which one I choose. I only have options that are the right version but seemingly python.exe files in the project, in my Windows directory and all over the place.
b) Settings>PythonInterpreter>VirtualEnvironment>ExisitngLocation
When I get it to work it's usually the python.exe in the Windows directory that pip installs everything in. Selecting that interpreter then locates all the packages I have installed and I can import all the libraries I want.
I would like to (i) understand why I have so many options (don't I just use python.exe because I've installed it somewhere) to pick a multitude of python.exe everytime I build a new project. I have missed this aspect of Python.
I would like to (ii) understand how to get a project to reference the libraries I have installed on my machine such that I can access them properly in my project and spend less time trying to wire everything up and more time actually building the project out.
I had a similar issue initially.
My "solution" was to delete python from the Windows Store, install Anaconda and then follow these steps from a SO answer for enabling PowerShell to run python with conda
Details in creating projects with PyCharm can be found here (a webpage on Anaconda).
Then PyCharm just works... like a charm.
I'm trying to install OpenCV into my python environment (Windows), and I'm almost all of the way there, but still having some issues with autocomplete and Pycharm itself importing the library. I've been through countless other related threads, but it seems like most of them are either outdated, for prebuilt versions, or unanswered.
I'm using Anaconda and have several environments, and unfortunately installing it through pip install opencv-contrib-python doesn't include everything I need. So, I've built it from source, and the library itself seem to be working fine. The build process installed some things into ./Anaconda3/envs/cv/Lib/site-packages/cv2/: __init__.py, some config py files, and .../cv2/python-3.8/cv2.cp38-win_amd64.pyd. I'm not sure if it did anything else.
But here's where I'm at:
In a separate environment, a pip install opencv-contrib-python both runs and has autocomplete working
In this environment, OpenCV actually runs just fine, but the autocomplete doesn't work and Pycharm complains about everything, eg: Cannot find reference 'imread' in '__init__.py'
Invalidate Caches / Restart doesn't help
Removing and re-adding the environment doesn't help
Deleting the user preferences folder for Pycharm doesn't help
Rebuilding/Installing OpenCV doesn't help
File->Settings->Project->Project Interpreter is set correctly
Run->Edit Configuration->Python Interpreter is set correctly
So my question is: how does Pycharm get or generate that autocomplete information? It looks like the pyd file is just a dll in disguise, and looking through the other environment's site-packages/cv2 folder, I don't see anything interesting. I've read that __init__.py has something to do with it, but again the pip version doesn't contain anything (except there's a from .cv2 import *, but I'm not sure how that factors in). The .whl file you can download is a zip that only contains the same as what 'pip install' gets.
Where does the autocomplete information get stored? Maybe there's some way to copy it from one environment to another? It would get me almost all the way there, which at this point would be good enough I think. Maybe I need to rebuild it with another flag I missed?
Got it finally! Figures that would happen just after posting the question...
Turns out .../envs/cv/site-packages/cv2/python-3.8/cv2.cp38-win_amd64.pyd needed to be copied to .../envs/cv/DLLs/. Then PyCharm did it's magic and is now all good.
Alternatively add the directory containing the .pyd file to the interpreter paths.
I had exactly this problem with OpenCV 4.2.0 compiled from sources, installed in my Conda environment and PyCharm 2020.1.
I solved this way:
Select project interpreter
Click on the settings button next to it and then clicking on the Show paths for selected interpreter
adding the directory containing the cv2 library (in my case in the Conda Python library path - e.g. miniconda3/lib/python3.7/site-packages/cv2/python-3.7). In general check the site-packages/cv2/python-X.X directory)
When I try to install TensorFlow using pip in the terminal (I'm on Mac), it says that I have it downloaded. The problem is when I try to use import tensorflow in pycharm it says that I do not have it installed. Please help.
Check your project interpreter on PyCharm. Based on your description, it seems like you might have installed TensorFlow on your base. If PyCharm's interpreter is using a different environment (that is not your base environment) to run Python, you will not be able to access TensorFlow. PyCharm allows users to configure environments and interpreters very easily.
I recommend that you use a virtual environment for your projects, since it allows you to manage different modules and installations more conveniently. For more information on Python virtual environments, refer to this post.
If anything is unclear, I'd be happy to elaborate.
I'm running MacOS Sierra 10.12.6
By default the system came with Python 2.7.10
I installed Python 3.6.3 (with IDLE) so I can learn Python (3). I understand that this is normal as MacOS may rely on Python 2.x for some programs. Either way, Python3 runs just fine if I run python3 from the command line/terminal, or if I use IDLE (which defaults to Python 3).
Now I want to install some libraries like Beautiful Soup.
And I believe I can install it as follows:
pip3 install beautifulsoup4
which should automatically install it. However, I read that it's recommended to use virtualenv on Mac BEFORE I run the above command. As a newbie, I don't want to mess anything up on my PC, so can anyone point me out how I can do this correctly?
For example, I can follow this link: http://sourabhbajaj.com/mac-setup/Python/virtualenv.html
But I just want to write here to make sure I'm following the right article/commands before I do it. Just being super careful!
Also, can I make a folder with my "virtual environment" and then add sub-folders inside that for each project? Meaning, I don't need to do this everytime, I have one virtual environment and any project that I do just is a subfolder within that space so I can use any libraries that I installed. Just trying to grasp the concept.
Thanks!
Sorry to add confusion.. this can be a tough subject for someone starting out.
The official docs recommend venv, which is similar to, but slightly different than virtualenv.
I would strongly recommend pycharm. It will create your venv for you as part of your project, which you might find helpful.
[Edit: Some other virtual environment features of pycharm that will help you].
If you type in an import statement for a package that isn't installed, it will offer to install it for you.
typing alt-F12 will bring you up a console with your virtual environment active
It syncs up your requirements.txt document for you
It manages your virtual environment path for you (as long as you are running inside pycharm), helping avoid import problems that many newcomers have with virtual environments.
I am not affiliated with pycharm, btw -- I just think it is a great tool for python developers, especially for newcomers, and its treatment of virtual environments is especially helpful.
You create one virtualenv for each project as a way of keeping track of the specific dependencies to keep them minimal which then makes it easier when you want to share projects with other people.
But this is not something you need. No harm comes from installing packages in your real environment as well. So you can safely run
pip3 install beautifulsoup4
I'm working on a script that will plot data onto a map using the Basemap library. I'm trying to import Shapely as well for use in this same script. I'm working with Anaconda2 for Python2.7 in a Windows 7 environment. I used conda install to download the tar.bz2 file from the Conda Packages site (using Windows command line) and it looked like it all installed correctly.
When I open Pycharm and look at my accessible site-packages, I can see this package. However, when I try to use it within my script, I get an error saying that the package does not exist. I ran the script through the debugger to see if it would shed any more light, but I got the same error. Here's a screenshot of my available site packages when I go to Settings-->Project Interpreter from within Pycharm.
Screenshot of PyCharm site packages available
Is there something special I need to do in order to access this package from within a fresh Python file? I was trying to say "import shapely" or "import osx-64-shapely", but both give me the same "package does not exist" error message. I've been able to successfully use other third-party libraries within Python, so I'm not quite sure what the error is here....
I'm new to SO - if you need more details or there's some piece of info I didn't include, please let me know. Thank you for your help!
EDIT: I am NOT asking what the difference is between conda and pip, or how to use pip within PyCharm. I have used both successfully before to install third-party libraries. What I am asking is what might cause a third-party library that appears to have installed successfully from the command line become inaccessible from within PyCharm when I attempt to import it.
I'm not familiar with Shapely but I was astonished to see the name osx-64-shapely as a site-package for your python installation which is in windows 7. Are you sure you downloaded the right file? :)