Heroku tutorial with PIP, virtualenv, psycopg2, Dj

2019-06-28 02:13发布

I've been doing a lot of reading lately about Heroku and I'm thinking about moving over to it. I thought I would give their little tutorial a try and play around with it a bit.

Ok. Time for a confession. While I have virtualenv installed, I don't really use it. I'm not a guy that has to switch between different projects very often (e.g. like a contractor my need to do). I really like the idea of it, but just not that experienced. I know everyone says that it's best practices these days.

The problem that I have is that I can't get pip to install psycopg2 (which is a part of the tutorial). Btw, here's a link to what I'm trying to do (heroku article)

So, this is not a new problem for me. I've never been able to get the thing to install via pip. I always get the problem

Unable to find vcvarsall.bat

The way that I've solved it in the past on a windows machine was to just download the prebuild libs. If anyone is interested and doesn't know, you can find these here! Btw, thank you Christoph Gohlke for maintaining these!!!!

If you search for this vcvarsall.bat error, you will find several posts for it on Stackoverflow. NONE of them helped me. I originally tried to go the MingGW route. After literally 2 nights of effort (and I think I tried every suggestion I could find), I quit trying (right before I threw my PC out the window and went on a kitten-killing rampage). So, I tried the other route that people suggest - which is to download VC++ 2008 Express edition from Microsoft. Apparently, Python for Windows is built with VC++ 2008 and for some people this is a much easier route than using MinGW. This seems to have worked much better for me, because I can at least get pip to install it. But, when I try to import, I get another common problem people seem to have (at least you get hits when you google it).

File "C:\foo\bar\venv\lib\site-packages\psycopg2__init __.py", line 67, in from psycopg2._psycopg import BINARY, NUMBER, STRING, DATETIME, ROWID ImportError: DLL load failed: The operating system cannot run %1.

After some research, it seems like this is a problem with the compiled _psycopg.pyd file trying to link in libpq.dll. This file is in C:\Program Files (x86)\PostgreSQL\9.1\bin\ - and that is in my path.

So, does anyone know how to fix this? Or is there a way to get pip to use pyscopg2 that is already successfully installed (via the prebuilt libs) in my site-packages? Note: I can make the problem go away if I just copy my prebuilt psycopg2 package into the site-packages of the virtual environment. it will import fine. However, when you do pip freeze for the requirements for heroku, it's not there. Is there a way to fake heroku out on this?

Environment is: Windows 7 (64bit), Python 2.6.5, Django 1.3.1, virtualenv 1.6.4, PostgreSQL 9.1, pip 1.0.2

4条回答
对你真心纯属浪费
2楼-- · 2019-06-28 02:45

Make sure:

Your distutils.cfg points to mingw
You have 32-bit PostgreSQL installed if you get ld errors on libpq.dll

查看更多
何必那么认真
3楼-- · 2019-06-28 02:46

I've run into all the issues you state so far and I'm trying to keep a log of what hoops I have to jump through to write a blog post on it later. I think the latest error you're seeing can be solved by simply adding the Postgres bin directory to you Windows Path environment variable.

查看更多
甜甜的少女心
4楼-- · 2019-06-28 02:53

I had the same exact problem as you, and have been trying to troubleshoot the problem.

After using Visual Basic 2008 to resolve my 'Unable to find vcvarsall.bat' error

I installed PostgreSQL (No need to load in anything from StackBuilder) and Heroku finally allowed me to deploy my Django app without problems. Installing PostgreSQL was a prerequisite for deploying your Django app (and is usually not seen, but it is on the top of the same page)!

Hope this helped you future users to resolve any similar problems you may of had.

查看更多
老娘就宠你
5楼-- · 2019-06-28 03:05

I've had the same set of experiences.

I noticed that when I try to manage.py runserver on an old app, it doesn't work in the virtualenv. When I run python.exe manage.py runserver, it works in the virtualenv.

Unfortunately, though, the trick doesn't quite seem to work on django-admin.py. I get the error: python.exe: can't open file 'django-admin.py' [Errno 2] No such file or directory

But when I start a python interpreter and import django, it works just fine.

Not sure if this helps, but figured it was worth a shot.

查看更多
登录 后发表回答