0

so I am a new Python user, just learning the ropes. I installed Python as a requirement for a course I am taking. My problem first arose when I used pip to install the 'bottle' package, which installed fine, however, when I try to access my .py file that uses bottle with the following command python C:\Python27\hello_bottle.py, I get an

ImportError: no module named bottle.

The frustrating part is that I could get bottle to work in other ways, the most prevalent one being: running Python, import sys, then appending sys.path to include the appropriate directory for my machine, which is C:\Python27\Lib\site-packages

When I did that, I was able to import and use bottle temporarily, however, it only worked for the current instance of Python, and I wanted a permanent solution. So, in my search for such a solution, I came accross the concept of setting up the environment variables PYTHONHOME and PYTHONPATH, which I promptly went about doing. Presently, they are set up as follows:

Path = C:\Program Files\MongoDB\Server\3.4\bin;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Python27;C:\Python27\Scripts;C:\Python27\Lib\site-packages;%PYTHONHOME%;%PYTHONPATH;

PYTHONHOME = C:\Python27

PYTHONPATH = C:\Python27\Lib;%PYTHONHOME%

Now, on account of this working when I ran the code in python earlier, setting up the sys.path variable, I thought I had my solution and that this would work. But, on the contrary, things got worse. Now, when I try to run Python from my cmd prompt (I use Babun), I get a new error: "ImportError: no module names site"

This is even more concerning, because after some research I found that this is what sets up the paths for Python, and now the entire program is not working. What's even more troubling, is that one time it just randomly worked without me changing anything, and then the next time I opened cmd it was back to not working again.

When I set the path variables the first time, I used the "export" command, then I reset them with the "setx" command, and finally I went into my system settings and just created the environment variables there (which is where I am at now).

Any help with this would be greatly appreciated, I'm pulling my hair out with frustration. Thank you!

Cheers, Jesse

Dan
  • 45,079
  • 17
  • 88
  • 157
Jesse Potter
  • 1
  • 1
  • 1
  • 1
  • install an editor like komodo edit. Make a folder like 'D:\testscripts" or "myscripts" add that to your windows path environment. NEVER EVER are your own scripts stored on C-drive due to disk-failure or randsomwere hyjack risks, etc. Also: "C:\Python27;C:\Python27\Scripts;C:\Python27\Lib\site-packages" use the '\' so it should be "C:\Python27;C:\Python27\Scripts;C:\Python27\Lib\site-packages\" – ZF007 Jan 23 '18 at 11:09
  • Ok, thank you! Is that only for my own scripts? Or do I need to move all my Python stuff over? Why is it a hyjack risk? How do people take advantage of that vulnerability? – Jesse Potter Jan 24 '18 at 02:34
  • Also, I'm probably sounding very noobish here, but I don't have a D:\ drive to make folders in. Do I need to partition my hard drive of something? – Jesse Potter Jan 24 '18 at 02:52
  • If there is a serious crash with your hdd its normally the c-drive that goes down as a sinking ship, which mean bye bye scripts you wrote, wave your mp3s and doc-files to the sewer too. There comes the d-drive (can be a particion or another hdd) to the rescue. Read more [here](https://www.pcworld.com/article/185941/how_and_why_to_partition_your_hard_drive.html) on how and why its good to have multiple partitions. – ZF007 Jan 24 '18 at 07:26
  • no need to move python. Just have a backup folder of program installers on separate partition/drive.. saves time with re-installation when needed. As you see you have no d-drive and... zillions with you! Thus malicious figures write malicious code for c-drive because that is 100% hit and how windows installs/operate from. – ZF007 Jan 24 '18 at 07:33
  • So.. yes make yourself a d-drive of minimum 20-50 GB as back-up drive for all your important documents and files. (e.g. your windows download folder is somewhere (c:\user\..app...\download) is on c-drive... if its piled with pdfs, prog-installers...etc.. remember to back them up elsewhere. unless you want spending days gathering what you may have lost in the future. – ZF007 Jan 24 '18 at 07:40

1 Answers1

0

Three things:

  1. site-pacakges has no business beeing in your PATH, remove it.
  2. In windows, PYTHONHOME should be C:\Python27\Lib or even better, be left alone, also you don't have to manually add it to PYTHONPATH.
  3. You should check out virtualenv.
yorodm
  • 4,359
  • 24
  • 32
  • I tried doing this, but things still aren't working. Now it just can't seem to locate the "bottle" package again, so back to square one. Maybe I need to reinstall Python... I did an $ unset on PYTHONHOME and PYTHONPATH, not sure if that is what screwed it up this time. – Jesse Potter Jan 26 '18 at 21:34
  • debian/ubuntu fix for this was: export PYTHONHOME=/usr ; export PYTHONPATH=/usr/lib64/python2.7:/usr/lib64/python2.7/lib-dynload – jmullee Jul 05 '21 at 11:16