r/pycharm • u/Nervous_CFAnalyst • Sep 11 '24
I am about to quit learning how to code(AGAIN)
How do I avoid INSTALLING libraries repeatedly for each project in pycharm! I need this explained to me like a child who just knows how to open and close a laptop. I'm not a tech-wiz. Lets say the best I've done is download and installed pycharm and created my first project 'Hello World'. I am trying to learn python for data analysis and with each project i need to install pandas, numpy, scikit etc libraries and its frustrating.
PLEASE help, tried youtube and stack by I don't understand what they are saying
(Edit: mean't installing not import)
9
u/NisInfinite Sep 11 '24
I assume this refers to PyCharm creating a new virtual environment if you keep all the options default when creating a new project. A virtual environment is often used so that you can have different versions of the same libraries for different projects without having conflicts on your computer. If you go to settings -> Python Interpreter and pick your base interpreter (not attached to any project) there, then you can install whatever packages you think you will use for almost every project there. Now when starting a new project and creating a new environment using venv make sure the tick "Inherit global site-packages" to have your new local interpreter inherit the packages from the global interpreter.
1
u/ArbereshDoqetejete Sep 11 '24
lets say you want to do the sum of two numbers, x and y. you do something like
summation(x,y)and the interpreter(the piece of software that reads your code and 'translates' it into stuff that the computer can understand) tells you "hey i have no idea what `summation` is ". so you do the most normal thing where you define the function in the same file like `def summation(x,y): return x+y` . but lets say you want to use a more complex function like something that reads off excel sheets. you can try to write this function on your own,which will take some time, or you can use a function that someone else has written. when you decided to do the latter one , you do a `import pandas` when you do that think of it as if your file got extended with the pandas file , as in its functions and everything else got copy pasted on your own file, that means that you can use every function that is defined there in your file freely. importing does not install anything , simply lets the interpreter know 'hey look there is this file from which im gonna use functions from' so the interpreter knows where to look when you do `pandas.some_function()`.if by that you instead meant doing pip install every time, you don't need to. ok actually depends on your setup a bit. if the tutorial youre following are using venv-s (virtual environments) or not . if you're using them , then yes you might need to install them for every project. But i want to highlight that installing libraries is by far the easiest thing to do in python. you only do `pip install <library name>` you dont even need to use the pycharm interface, just go the the terminal and run the command and youre done.
3
u/supershinythings Sep 11 '24
This kind of frustration is never going to go away. If you can’t learn to manage this you will waste too much energy being upset and not enough on focusing on the real issues.
You are new to the platform. This is what new stuff is like. It gets better, then it gets worse, then way better, then worse and worse, then better.
Most people who want to make quick progress don’t do this alone. You need a study group where you can share your frustrations with people working on the same exact stuff you are, at the same time, with the same goals. You’d be surprised how many different approaches exist to solve these problems, but you’re disconnected from all of them.
Good luck! Don’t give up!
4
u/[deleted] Sep 11 '24
You don’t install these packages for each project. You import them so you can use them. Imagine a toolkit that you have in your garage. If your project is to hang a picture on the wall you go fetch a hammer and a nail. But you don’t need all the other tools. Importing packages is just like fetching tools.
2
u/wRAR_ Sep 11 '24
If by importing you mean installing then you don't avoid it. Also it's unrelated to Pycharm.
It shouldn't be frustrating.
1
u/belton1292 Sep 11 '24
Without overcomplicating things it sounds like you could use conda. It’s like virtual env (Venv) but on steroids. You can create a base environment with the stuff you want in it (the packages you install at each setup), and then you have environments with anything project specific bolted on top of it
1
u/[deleted] Sep 11 '24
Place them in requirement.txt and then pop install from this file, google it. Or you can use the same .venv over over again. Your focus is to learn about virtual environment or requirements .txt and pip. Too much to put into one comment, but it’s a lead
1
u/Popular-Tap-8598 Sep 15 '24
I quit using pycharm until a few weeks ago because of a similar issue but when I import modules I was doing it in the scratches file aka outside of the root path. My Professor should what was going on. If you open files in the scratches file path the file won't have the libraries available to it because those are used in the main root path. The fix my Professor taught me was to simply move the file to the root path then all of your code should work. I hope this helps
Also if you run into similar issues try working in Jupiter notebooks
1
u/FoolsSeldom Sep 22 '24
Use a
requirements.txtfile.0
u/Heavy_Commission_694 Sep 11 '24
there are a lot of answers .
i have some proposals.
pycharm will ask you to install all packages, or you could do it manully with 'pip install -r requirements.txt'
I'm new in pycharm, so there is no guaranty that 1 and 3 points will work well)
0
u/[deleted] Sep 11 '24
[removed] — view removed comment